
Use [NetROS]
Go
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsoba_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsoba_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsoba_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsoba_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Ime],
					[Prezime],
					[IDMjestoRodenja],
					[MBG],
					[OIB],
					[ImeOca],
					[ImeMajke],
					[DatumRodenja],
					[Napomena],
					[OsobniOdbitak],
					[Spol],
					[StrucnaSprema],
					[Drzavljanstvo],
					[RadnaDozvolaDaNe],
					[RadnaDozvolaDatumIsteka],
					[Obrazovanje],
					[StazDoDolaska]
				FROM
					[pla].[tblOsoba]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsoba_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsoba_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsoba_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsoba table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsoba_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Ime]'
				SET @SQL = @SQL + ', [Prezime]'
				SET @SQL = @SQL + ', [IDMjestoRodenja]'
				SET @SQL = @SQL + ', [MBG]'
				SET @SQL = @SQL + ', [OIB]'
				SET @SQL = @SQL + ', [ImeOca]'
				SET @SQL = @SQL + ', [ImeMajke]'
				SET @SQL = @SQL + ', [DatumRodenja]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [OsobniOdbitak]'
				SET @SQL = @SQL + ', [Spol]'
				SET @SQL = @SQL + ', [StrucnaSprema]'
				SET @SQL = @SQL + ', [Drzavljanstvo]'
				SET @SQL = @SQL + ', [RadnaDozvolaDaNe]'
				SET @SQL = @SQL + ', [RadnaDozvolaDatumIsteka]'
				SET @SQL = @SQL + ', [Obrazovanje]'
				SET @SQL = @SQL + ', [StazDoDolaska]'
				SET @SQL = @SQL + ' FROM [pla].[tblOsoba]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Ime],'
				SET @SQL = @SQL + ' [Prezime],'
				SET @SQL = @SQL + ' [IDMjestoRodenja],'
				SET @SQL = @SQL + ' [MBG],'
				SET @SQL = @SQL + ' [OIB],'
				SET @SQL = @SQL + ' [ImeOca],'
				SET @SQL = @SQL + ' [ImeMajke],'
				SET @SQL = @SQL + ' [DatumRodenja],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [OsobniOdbitak],'
				SET @SQL = @SQL + ' [Spol],'
				SET @SQL = @SQL + ' [StrucnaSprema],'
				SET @SQL = @SQL + ' [Drzavljanstvo],'
				SET @SQL = @SQL + ' [RadnaDozvolaDaNe],'
				SET @SQL = @SQL + ' [RadnaDozvolaDatumIsteka],'
				SET @SQL = @SQL + ' [Obrazovanje],'
				SET @SQL = @SQL + ' [StazDoDolaska]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOsoba]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsoba_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsoba_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsoba_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsoba_Insert
(

	@ID int    OUTPUT,

	@Ime nvarchar (100)  ,

	@Prezime nvarchar (100)  ,

	@IDMjestoRodenja int   ,

	@MBG nvarchar (13)  ,

	@OIB nvarchar (11)  ,

	@ImeOca nvarchar (100)  ,

	@ImeMajke nvarchar (100)  ,

	@DatumRodenja datetime   ,

	@Napomena nvarchar (300)  ,

	@OsobniOdbitak real   ,

	@Spol int   ,

	@StrucnaSprema int   ,

	@Drzavljanstvo nvarchar (50)  ,

	@RadnaDozvolaDaNe int   ,

	@RadnaDozvolaDatumIsteka datetime   ,

	@Obrazovanje nvarchar (200)  ,

	@StazDoDolaska nvarchar (6)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOsoba]
					(
					[Ime]
					,[Prezime]
					,[IDMjestoRodenja]
					,[MBG]
					,[OIB]
					,[ImeOca]
					,[ImeMajke]
					,[DatumRodenja]
					,[Napomena]
					,[OsobniOdbitak]
					,[Spol]
					,[StrucnaSprema]
					,[Drzavljanstvo]
					,[RadnaDozvolaDaNe]
					,[RadnaDozvolaDatumIsteka]
					,[Obrazovanje]
					,[StazDoDolaska]
					)
				VALUES
					(
					@Ime
					,@Prezime
					,@IDMjestoRodenja
					,@MBG
					,@OIB
					,@ImeOca
					,@ImeMajke
					,@DatumRodenja
					,@Napomena
					,@OsobniOdbitak
					,@Spol
					,@StrucnaSprema
					,@Drzavljanstvo
					,@RadnaDozvolaDaNe
					,@RadnaDozvolaDatumIsteka
					,@Obrazovanje
					,@StazDoDolaska
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsoba_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsoba_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsoba_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsoba_Update
(

	@ID int   ,

	@Ime nvarchar (100)  ,

	@Prezime nvarchar (100)  ,

	@IDMjestoRodenja int   ,

	@MBG nvarchar (13)  ,

	@OIB nvarchar (11)  ,

	@ImeOca nvarchar (100)  ,

	@ImeMajke nvarchar (100)  ,

	@DatumRodenja datetime   ,

	@Napomena nvarchar (300)  ,

	@OsobniOdbitak real   ,

	@Spol int   ,

	@StrucnaSprema int   ,

	@Drzavljanstvo nvarchar (50)  ,

	@RadnaDozvolaDaNe int   ,

	@RadnaDozvolaDatumIsteka datetime   ,

	@Obrazovanje nvarchar (200)  ,

	@StazDoDolaska nvarchar (6)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOsoba]
				SET
					[Ime] = @Ime
					,[Prezime] = @Prezime
					,[IDMjestoRodenja] = @IDMjestoRodenja
					,[MBG] = @MBG
					,[OIB] = @OIB
					,[ImeOca] = @ImeOca
					,[ImeMajke] = @ImeMajke
					,[DatumRodenja] = @DatumRodenja
					,[Napomena] = @Napomena
					,[OsobniOdbitak] = @OsobniOdbitak
					,[Spol] = @Spol
					,[StrucnaSprema] = @StrucnaSprema
					,[Drzavljanstvo] = @Drzavljanstvo
					,[RadnaDozvolaDaNe] = @RadnaDozvolaDaNe
					,[RadnaDozvolaDatumIsteka] = @RadnaDozvolaDatumIsteka
					,[Obrazovanje] = @Obrazovanje
					,[StazDoDolaska] = @StazDoDolaska
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsoba_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsoba_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsoba_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsoba_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOsoba] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsoba_GetByIDMjestoRodenja procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsoba_GetByIDMjestoRodenja') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsoba_GetByIDMjestoRodenja
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsoba table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsoba_GetByIDMjestoRodenja
(

	@IDMjestoRodenja int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Ime],
					[Prezime],
					[IDMjestoRodenja],
					[MBG],
					[OIB],
					[ImeOca],
					[ImeMajke],
					[DatumRodenja],
					[Napomena],
					[OsobniOdbitak],
					[Spol],
					[StrucnaSprema],
					[Drzavljanstvo],
					[RadnaDozvolaDaNe],
					[RadnaDozvolaDatumIsteka],
					[Obrazovanje],
					[StazDoDolaska]
				FROM
					[pla].[tblOsoba]
				WHERE
					[IDMjestoRodenja] = @IDMjestoRodenja
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsoba_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsoba_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsoba_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsoba table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsoba_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Ime],
					[Prezime],
					[IDMjestoRodenja],
					[MBG],
					[OIB],
					[ImeOca],
					[ImeMajke],
					[DatumRodenja],
					[Napomena],
					[OsobniOdbitak],
					[Spol],
					[StrucnaSprema],
					[Drzavljanstvo],
					[RadnaDozvolaDaNe],
					[RadnaDozvolaDatumIsteka],
					[Obrazovanje],
					[StazDoDolaska]
				FROM
					[pla].[tblOsoba]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsoba_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsoba_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsoba_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsoba table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsoba_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Ime nvarchar (100)  = null ,

	@Prezime nvarchar (100)  = null ,

	@IDMjestoRodenja int   = null ,

	@MBG nvarchar (13)  = null ,

	@OIB nvarchar (11)  = null ,

	@ImeOca nvarchar (100)  = null ,

	@ImeMajke nvarchar (100)  = null ,

	@DatumRodenja datetime   = null ,

	@Napomena nvarchar (300)  = null ,

	@OsobniOdbitak real   = null ,

	@Spol int   = null ,

	@StrucnaSprema int   = null ,

	@Drzavljanstvo nvarchar (50)  = null ,

	@RadnaDozvolaDaNe int   = null ,

	@RadnaDozvolaDatumIsteka datetime   = null ,

	@Obrazovanje nvarchar (200)  = null ,

	@StazDoDolaska nvarchar (6)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Ime]
	, [Prezime]
	, [IDMjestoRodenja]
	, [MBG]
	, [OIB]
	, [ImeOca]
	, [ImeMajke]
	, [DatumRodenja]
	, [Napomena]
	, [OsobniOdbitak]
	, [Spol]
	, [StrucnaSprema]
	, [Drzavljanstvo]
	, [RadnaDozvolaDaNe]
	, [RadnaDozvolaDatumIsteka]
	, [Obrazovanje]
	, [StazDoDolaska]
    FROM
	[pla].[tblOsoba]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Ime] = @Ime OR @Ime is null)
	AND ([Prezime] = @Prezime OR @Prezime is null)
	AND ([IDMjestoRodenja] = @IDMjestoRodenja OR @IDMjestoRodenja is null)
	AND ([MBG] = @MBG OR @MBG is null)
	AND ([OIB] = @OIB OR @OIB is null)
	AND ([ImeOca] = @ImeOca OR @ImeOca is null)
	AND ([ImeMajke] = @ImeMajke OR @ImeMajke is null)
	AND ([DatumRodenja] = @DatumRodenja OR @DatumRodenja is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([OsobniOdbitak] = @OsobniOdbitak OR @OsobniOdbitak is null)
	AND ([Spol] = @Spol OR @Spol is null)
	AND ([StrucnaSprema] = @StrucnaSprema OR @StrucnaSprema is null)
	AND ([Drzavljanstvo] = @Drzavljanstvo OR @Drzavljanstvo is null)
	AND ([RadnaDozvolaDaNe] = @RadnaDozvolaDaNe OR @RadnaDozvolaDaNe is null)
	AND ([RadnaDozvolaDatumIsteka] = @RadnaDozvolaDatumIsteka OR @RadnaDozvolaDatumIsteka is null)
	AND ([Obrazovanje] = @Obrazovanje OR @Obrazovanje is null)
	AND ([StazDoDolaska] = @StazDoDolaska OR @StazDoDolaska is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Ime]
	, [Prezime]
	, [IDMjestoRodenja]
	, [MBG]
	, [OIB]
	, [ImeOca]
	, [ImeMajke]
	, [DatumRodenja]
	, [Napomena]
	, [OsobniOdbitak]
	, [Spol]
	, [StrucnaSprema]
	, [Drzavljanstvo]
	, [RadnaDozvolaDaNe]
	, [RadnaDozvolaDatumIsteka]
	, [Obrazovanje]
	, [StazDoDolaska]
    FROM
	[pla].[tblOsoba]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Ime] = @Ime AND @Ime is not null)
	OR ([Prezime] = @Prezime AND @Prezime is not null)
	OR ([IDMjestoRodenja] = @IDMjestoRodenja AND @IDMjestoRodenja is not null)
	OR ([MBG] = @MBG AND @MBG is not null)
	OR ([OIB] = @OIB AND @OIB is not null)
	OR ([ImeOca] = @ImeOca AND @ImeOca is not null)
	OR ([ImeMajke] = @ImeMajke AND @ImeMajke is not null)
	OR ([DatumRodenja] = @DatumRodenja AND @DatumRodenja is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([OsobniOdbitak] = @OsobniOdbitak AND @OsobniOdbitak is not null)
	OR ([Spol] = @Spol AND @Spol is not null)
	OR ([StrucnaSprema] = @StrucnaSprema AND @StrucnaSprema is not null)
	OR ([Drzavljanstvo] = @Drzavljanstvo AND @Drzavljanstvo is not null)
	OR ([RadnaDozvolaDaNe] = @RadnaDozvolaDaNe AND @RadnaDozvolaDaNe is not null)
	OR ([RadnaDozvolaDatumIsteka] = @RadnaDozvolaDatumIsteka AND @RadnaDozvolaDatumIsteka is not null)
	OR ([Obrazovanje] = @Obrazovanje AND @Obrazovanje is not null)
	OR ([StazDoDolaska] = @StazDoDolaska AND @StazDoDolaska is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaBankovniRacun_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaBankovniRacun_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaBankovniRacun_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsobaBankovniRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaBankovniRacun_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[BrojRacuna],
					[ModelZaIsplatuPlace],
					[PozivNaBrojZaIsplatuPlace],
					[IDOsoba],
					[DatumOd],
					[DatumDo],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[BrojRacuna2]
				FROM
					[pla].[tblOsobaBankovniRacun]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaBankovniRacun_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaBankovniRacun_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaBankovniRacun_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsobaBankovniRacun table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaBankovniRacun_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [BrojRacuna]'
				SET @SQL = @SQL + ', [ModelZaIsplatuPlace]'
				SET @SQL = @SQL + ', [PozivNaBrojZaIsplatuPlace]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [PrimateljNaziv]'
				SET @SQL = @SQL + ', [PrimateljSjediste]'
				SET @SQL = @SQL + ', [BrojRacuna2]'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaBankovniRacun]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [BrojRacuna],'
				SET @SQL = @SQL + ' [ModelZaIsplatuPlace],'
				SET @SQL = @SQL + ' [PozivNaBrojZaIsplatuPlace],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [PrimateljNaziv],'
				SET @SQL = @SQL + ' [PrimateljSjediste],'
				SET @SQL = @SQL + ' [BrojRacuna2]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaBankovniRacun]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaBankovniRacun_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaBankovniRacun_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaBankovniRacun_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsobaBankovniRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaBankovniRacun_Insert
(

	@ID int    OUTPUT,

	@BrojRacuna nvarchar (20)  ,

	@ModelZaIsplatuPlace nvarchar (2)  ,

	@PozivNaBrojZaIsplatuPlace nvarchar (23)  ,

	@IDOsoba int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@PrimateljNaziv nvarchar (50)  ,

	@PrimateljSjediste nvarchar (50)  ,

	@BrojRacuna2 nvarchar (20)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOsobaBankovniRacun]
					(
					[BrojRacuna]
					,[ModelZaIsplatuPlace]
					,[PozivNaBrojZaIsplatuPlace]
					,[IDOsoba]
					,[DatumOd]
					,[DatumDo]
					,[PrimateljNaziv]
					,[PrimateljSjediste]
					,[BrojRacuna2]
					)
				VALUES
					(
					@BrojRacuna
					,@ModelZaIsplatuPlace
					,@PozivNaBrojZaIsplatuPlace
					,@IDOsoba
					,@DatumOd
					,@DatumDo
					,@PrimateljNaziv
					,@PrimateljSjediste
					,@BrojRacuna2
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaBankovniRacun_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaBankovniRacun_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaBankovniRacun_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsobaBankovniRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaBankovniRacun_Update
(

	@ID int   ,

	@BrojRacuna nvarchar (20)  ,

	@ModelZaIsplatuPlace nvarchar (2)  ,

	@PozivNaBrojZaIsplatuPlace nvarchar (23)  ,

	@IDOsoba int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@PrimateljNaziv nvarchar (50)  ,

	@PrimateljSjediste nvarchar (50)  ,

	@BrojRacuna2 nvarchar (20)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOsobaBankovniRacun]
				SET
					[BrojRacuna] = @BrojRacuna
					,[ModelZaIsplatuPlace] = @ModelZaIsplatuPlace
					,[PozivNaBrojZaIsplatuPlace] = @PozivNaBrojZaIsplatuPlace
					,[IDOsoba] = @IDOsoba
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[PrimateljNaziv] = @PrimateljNaziv
					,[PrimateljSjediste] = @PrimateljSjediste
					,[BrojRacuna2] = @BrojRacuna2
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaBankovniRacun_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaBankovniRacun_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaBankovniRacun_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsobaBankovniRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaBankovniRacun_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOsobaBankovniRacun] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaBankovniRacun_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaBankovniRacun_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaBankovniRacun_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaBankovniRacun table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaBankovniRacun_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[BrojRacuna],
					[ModelZaIsplatuPlace],
					[PozivNaBrojZaIsplatuPlace],
					[IDOsoba],
					[DatumOd],
					[DatumDo],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[BrojRacuna2]
				FROM
					[pla].[tblOsobaBankovniRacun]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaBankovniRacun_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaBankovniRacun_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaBankovniRacun_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaBankovniRacun table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaBankovniRacun_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[BrojRacuna],
					[ModelZaIsplatuPlace],
					[PozivNaBrojZaIsplatuPlace],
					[IDOsoba],
					[DatumOd],
					[DatumDo],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[BrojRacuna2]
				FROM
					[pla].[tblOsobaBankovniRacun]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaBankovniRacun_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaBankovniRacun_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaBankovniRacun_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsobaBankovniRacun table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaBankovniRacun_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@BrojRacuna nvarchar (20)  = null ,

	@ModelZaIsplatuPlace nvarchar (2)  = null ,

	@PozivNaBrojZaIsplatuPlace nvarchar (23)  = null ,

	@IDOsoba int   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@PrimateljNaziv nvarchar (50)  = null ,

	@PrimateljSjediste nvarchar (50)  = null ,

	@BrojRacuna2 nvarchar (20)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [BrojRacuna]
	, [ModelZaIsplatuPlace]
	, [PozivNaBrojZaIsplatuPlace]
	, [IDOsoba]
	, [DatumOd]
	, [DatumDo]
	, [PrimateljNaziv]
	, [PrimateljSjediste]
	, [BrojRacuna2]
    FROM
	[pla].[tblOsobaBankovniRacun]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([BrojRacuna] = @BrojRacuna OR @BrojRacuna is null)
	AND ([ModelZaIsplatuPlace] = @ModelZaIsplatuPlace OR @ModelZaIsplatuPlace is null)
	AND ([PozivNaBrojZaIsplatuPlace] = @PozivNaBrojZaIsplatuPlace OR @PozivNaBrojZaIsplatuPlace is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([PrimateljNaziv] = @PrimateljNaziv OR @PrimateljNaziv is null)
	AND ([PrimateljSjediste] = @PrimateljSjediste OR @PrimateljSjediste is null)
	AND ([BrojRacuna2] = @BrojRacuna2 OR @BrojRacuna2 is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [BrojRacuna]
	, [ModelZaIsplatuPlace]
	, [PozivNaBrojZaIsplatuPlace]
	, [IDOsoba]
	, [DatumOd]
	, [DatumDo]
	, [PrimateljNaziv]
	, [PrimateljSjediste]
	, [BrojRacuna2]
    FROM
	[pla].[tblOsobaBankovniRacun]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([BrojRacuna] = @BrojRacuna AND @BrojRacuna is not null)
	OR ([ModelZaIsplatuPlace] = @ModelZaIsplatuPlace AND @ModelZaIsplatuPlace is not null)
	OR ([PozivNaBrojZaIsplatuPlace] = @PozivNaBrojZaIsplatuPlace AND @PozivNaBrojZaIsplatuPlace is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([PrimateljNaziv] = @PrimateljNaziv AND @PrimateljNaziv is not null)
	OR ([PrimateljSjediste] = @PrimateljSjediste AND @PrimateljSjediste is not null)
	OR ([BrojRacuna2] = @BrojRacuna2 AND @BrojRacuna2 is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPlaca_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPlaca_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPlaca_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsobaPlaca table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPlaca_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Iznos],
					[Neto],
					[DatumOd],
					[DatumDo],
					[Napomena],
					[IDOsoba],
					[IDPrimanjeTip],
					[DnevniBrojRadnihSati],
					[SubotaRadna],
					[StazMjeseci1],
					[StazMjeseci2],
					[MIO1],
					[MIO2],
					[StazSPovecanimTrajanjemRegos],
					[DoprinosNaPlace]
				FROM
					[pla].[tblOsobaPlaca]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPlaca_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPlaca_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPlaca_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsobaPlaca table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPlaca_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [Neto]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [IDPrimanjeTip]'
				SET @SQL = @SQL + ', [DnevniBrojRadnihSati]'
				SET @SQL = @SQL + ', [SubotaRadna]'
				SET @SQL = @SQL + ', [StazMjeseci1]'
				SET @SQL = @SQL + ', [StazMjeseci2]'
				SET @SQL = @SQL + ', [MIO1]'
				SET @SQL = @SQL + ', [MIO2]'
				SET @SQL = @SQL + ', [StazSPovecanimTrajanjemRegos]'
				SET @SQL = @SQL + ', [DoprinosNaPlace]'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaPlaca]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [Neto],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [IDPrimanjeTip],'
				SET @SQL = @SQL + ' [DnevniBrojRadnihSati],'
				SET @SQL = @SQL + ' [SubotaRadna],'
				SET @SQL = @SQL + ' [StazMjeseci1],'
				SET @SQL = @SQL + ' [StazMjeseci2],'
				SET @SQL = @SQL + ' [MIO1],'
				SET @SQL = @SQL + ' [MIO2],'
				SET @SQL = @SQL + ' [StazSPovecanimTrajanjemRegos],'
				SET @SQL = @SQL + ' [DoprinosNaPlace]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaPlaca]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPlaca_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPlaca_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPlaca_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsobaPlaca table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPlaca_Insert
(

	@ID int    OUTPUT,

	@Iznos money   ,

	@Neto bit   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@Napomena nvarchar (300)  ,

	@IDOsoba int   ,

	@IDPrimanjeTip int   ,

	@DnevniBrojRadnihSati money   ,

	@SubotaRadna bit   ,

	@StazMjeseci1 int   ,

	@StazMjeseci2 int   ,

	@MIO1 bit   ,

	@MIO2 bit   ,

	@StazSPovecanimTrajanjemRegos int   ,

	@DoprinosNaPlace bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOsobaPlaca]
					(
					[Iznos]
					,[Neto]
					,[DatumOd]
					,[DatumDo]
					,[Napomena]
					,[IDOsoba]
					,[IDPrimanjeTip]
					,[DnevniBrojRadnihSati]
					,[SubotaRadna]
					,[StazMjeseci1]
					,[StazMjeseci2]
					,[MIO1]
					,[MIO2]
					,[StazSPovecanimTrajanjemRegos]
					,[DoprinosNaPlace]
					)
				VALUES
					(
					@Iznos
					,@Neto
					,@DatumOd
					,@DatumDo
					,@Napomena
					,@IDOsoba
					,@IDPrimanjeTip
					,@DnevniBrojRadnihSati
					,@SubotaRadna
					,@StazMjeseci1
					,@StazMjeseci2
					,@MIO1
					,@MIO2
					,@StazSPovecanimTrajanjemRegos
					,@DoprinosNaPlace
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPlaca_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPlaca_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPlaca_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsobaPlaca table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPlaca_Update
(

	@ID int   ,

	@Iznos money   ,

	@Neto bit   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@Napomena nvarchar (300)  ,

	@IDOsoba int   ,

	@IDPrimanjeTip int   ,

	@DnevniBrojRadnihSati money   ,

	@SubotaRadna bit   ,

	@StazMjeseci1 int   ,

	@StazMjeseci2 int   ,

	@MIO1 bit   ,

	@MIO2 bit   ,

	@StazSPovecanimTrajanjemRegos int   ,

	@DoprinosNaPlace bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOsobaPlaca]
				SET
					[Iznos] = @Iznos
					,[Neto] = @Neto
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[Napomena] = @Napomena
					,[IDOsoba] = @IDOsoba
					,[IDPrimanjeTip] = @IDPrimanjeTip
					,[DnevniBrojRadnihSati] = @DnevniBrojRadnihSati
					,[SubotaRadna] = @SubotaRadna
					,[StazMjeseci1] = @StazMjeseci1
					,[StazMjeseci2] = @StazMjeseci2
					,[MIO1] = @MIO1
					,[MIO2] = @MIO2
					,[StazSPovecanimTrajanjemRegos] = @StazSPovecanimTrajanjemRegos
					,[DoprinosNaPlace] = @DoprinosNaPlace
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPlaca_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPlaca_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPlaca_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsobaPlaca table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPlaca_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOsobaPlaca] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPlaca_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPlaca_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPlaca_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaPlaca table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPlaca_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Iznos],
					[Neto],
					[DatumOd],
					[DatumDo],
					[Napomena],
					[IDOsoba],
					[IDPrimanjeTip],
					[DnevniBrojRadnihSati],
					[SubotaRadna],
					[StazMjeseci1],
					[StazMjeseci2],
					[MIO1],
					[MIO2],
					[StazSPovecanimTrajanjemRegos],
					[DoprinosNaPlace]
				FROM
					[pla].[tblOsobaPlaca]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPlaca_GetByIDPrimanjeTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPlaca_GetByIDPrimanjeTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPlaca_GetByIDPrimanjeTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaPlaca table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPlaca_GetByIDPrimanjeTip
(

	@IDPrimanjeTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Iznos],
					[Neto],
					[DatumOd],
					[DatumDo],
					[Napomena],
					[IDOsoba],
					[IDPrimanjeTip],
					[DnevniBrojRadnihSati],
					[SubotaRadna],
					[StazMjeseci1],
					[StazMjeseci2],
					[MIO1],
					[MIO2],
					[StazSPovecanimTrajanjemRegos],
					[DoprinosNaPlace]
				FROM
					[pla].[tblOsobaPlaca]
				WHERE
					[IDPrimanjeTip] = @IDPrimanjeTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPlaca_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPlaca_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPlaca_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaPlaca table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPlaca_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Iznos],
					[Neto],
					[DatumOd],
					[DatumDo],
					[Napomena],
					[IDOsoba],
					[IDPrimanjeTip],
					[DnevniBrojRadnihSati],
					[SubotaRadna],
					[StazMjeseci1],
					[StazMjeseci2],
					[MIO1],
					[MIO2],
					[StazSPovecanimTrajanjemRegos],
					[DoprinosNaPlace]
				FROM
					[pla].[tblOsobaPlaca]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPlaca_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPlaca_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPlaca_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsobaPlaca table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPlaca_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Iznos money   = null ,

	@Neto bit   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@Napomena nvarchar (300)  = null ,

	@IDOsoba int   = null ,

	@IDPrimanjeTip int   = null ,

	@DnevniBrojRadnihSati money   = null ,

	@SubotaRadna bit   = null ,

	@StazMjeseci1 int   = null ,

	@StazMjeseci2 int   = null ,

	@MIO1 bit   = null ,

	@MIO2 bit   = null ,

	@StazSPovecanimTrajanjemRegos int   = null ,

	@DoprinosNaPlace bit   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Iznos]
	, [Neto]
	, [DatumOd]
	, [DatumDo]
	, [Napomena]
	, [IDOsoba]
	, [IDPrimanjeTip]
	, [DnevniBrojRadnihSati]
	, [SubotaRadna]
	, [StazMjeseci1]
	, [StazMjeseci2]
	, [MIO1]
	, [MIO2]
	, [StazSPovecanimTrajanjemRegos]
	, [DoprinosNaPlace]
    FROM
	[pla].[tblOsobaPlaca]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
	AND ([Neto] = @Neto OR @Neto is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([IDPrimanjeTip] = @IDPrimanjeTip OR @IDPrimanjeTip is null)
	AND ([DnevniBrojRadnihSati] = @DnevniBrojRadnihSati OR @DnevniBrojRadnihSati is null)
	AND ([SubotaRadna] = @SubotaRadna OR @SubotaRadna is null)
	AND ([StazMjeseci1] = @StazMjeseci1 OR @StazMjeseci1 is null)
	AND ([StazMjeseci2] = @StazMjeseci2 OR @StazMjeseci2 is null)
	AND ([MIO1] = @MIO1 OR @MIO1 is null)
	AND ([MIO2] = @MIO2 OR @MIO2 is null)
	AND ([StazSPovecanimTrajanjemRegos] = @StazSPovecanimTrajanjemRegos OR @StazSPovecanimTrajanjemRegos is null)
	AND ([DoprinosNaPlace] = @DoprinosNaPlace OR @DoprinosNaPlace is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Iznos]
	, [Neto]
	, [DatumOd]
	, [DatumDo]
	, [Napomena]
	, [IDOsoba]
	, [IDPrimanjeTip]
	, [DnevniBrojRadnihSati]
	, [SubotaRadna]
	, [StazMjeseci1]
	, [StazMjeseci2]
	, [MIO1]
	, [MIO2]
	, [StazSPovecanimTrajanjemRegos]
	, [DoprinosNaPlace]
    FROM
	[pla].[tblOsobaPlaca]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	OR ([Neto] = @Neto AND @Neto is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([IDPrimanjeTip] = @IDPrimanjeTip AND @IDPrimanjeTip is not null)
	OR ([DnevniBrojRadnihSati] = @DnevniBrojRadnihSati AND @DnevniBrojRadnihSati is not null)
	OR ([SubotaRadna] = @SubotaRadna AND @SubotaRadna is not null)
	OR ([StazMjeseci1] = @StazMjeseci1 AND @StazMjeseci1 is not null)
	OR ([StazMjeseci2] = @StazMjeseci2 AND @StazMjeseci2 is not null)
	OR ([MIO1] = @MIO1 AND @MIO1 is not null)
	OR ([MIO2] = @MIO2 AND @MIO2 is not null)
	OR ([StazSPovecanimTrajanjemRegos] = @StazSPovecanimTrajanjemRegos AND @StazSPovecanimTrajanjemRegos is not null)
	OR ([DoprinosNaPlace] = @DoprinosNaPlace AND @DoprinosNaPlace is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaOrganizacijskaJedinica_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaOrganizacijskaJedinica_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaOrganizacijskaJedinica_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsobaOrganizacijskaJedinica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaOrganizacijskaJedinica_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[IDOrganizacijskaJedinica],
					[DatumOd],
					[DatumDo]
				FROM
					[pla].[tblOsobaOrganizacijskaJedinica]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaOrganizacijskaJedinica_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaOrganizacijskaJedinica_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaOrganizacijskaJedinica_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsobaOrganizacijskaJedinica table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaOrganizacijskaJedinica_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [IDOrganizacijskaJedinica]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaOrganizacijskaJedinica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [IDOrganizacijskaJedinica],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaOrganizacijskaJedinica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaOrganizacijskaJedinica_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaOrganizacijskaJedinica_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaOrganizacijskaJedinica_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsobaOrganizacijskaJedinica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaOrganizacijskaJedinica_Insert
(

	@ID int    OUTPUT,

	@IDOsoba int   ,

	@IDOrganizacijskaJedinica int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOsobaOrganizacijskaJedinica]
					(
					[IDOsoba]
					,[IDOrganizacijskaJedinica]
					,[DatumOd]
					,[DatumDo]
					)
				VALUES
					(
					@IDOsoba
					,@IDOrganizacijskaJedinica
					,@DatumOd
					,@DatumDo
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaOrganizacijskaJedinica_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaOrganizacijskaJedinica_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaOrganizacijskaJedinica_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsobaOrganizacijskaJedinica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaOrganizacijskaJedinica_Update
(

	@ID int   ,

	@IDOsoba int   ,

	@IDOrganizacijskaJedinica int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOsobaOrganizacijskaJedinica]
				SET
					[IDOsoba] = @IDOsoba
					,[IDOrganizacijskaJedinica] = @IDOrganizacijskaJedinica
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaOrganizacijskaJedinica_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaOrganizacijskaJedinica_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaOrganizacijskaJedinica_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsobaOrganizacijskaJedinica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaOrganizacijskaJedinica_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOsobaOrganizacijskaJedinica] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaOrganizacijskaJedinica_GetByIDOrganizacijskaJedinica procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaOrganizacijskaJedinica_GetByIDOrganizacijskaJedinica') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaOrganizacijskaJedinica_GetByIDOrganizacijskaJedinica
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaOrganizacijskaJedinica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaOrganizacijskaJedinica_GetByIDOrganizacijskaJedinica
(

	@IDOrganizacijskaJedinica int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[IDOrganizacijskaJedinica],
					[DatumOd],
					[DatumDo]
				FROM
					[pla].[tblOsobaOrganizacijskaJedinica]
				WHERE
					[IDOrganizacijskaJedinica] = @IDOrganizacijskaJedinica
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaOrganizacijskaJedinica_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaOrganizacijskaJedinica_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaOrganizacijskaJedinica_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaOrganizacijskaJedinica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaOrganizacijskaJedinica_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[IDOrganizacijskaJedinica],
					[DatumOd],
					[DatumDo]
				FROM
					[pla].[tblOsobaOrganizacijskaJedinica]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaOrganizacijskaJedinica_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaOrganizacijskaJedinica_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaOrganizacijskaJedinica_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaOrganizacijskaJedinica table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaOrganizacijskaJedinica_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOsoba],
					[IDOrganizacijskaJedinica],
					[DatumOd],
					[DatumDo]
				FROM
					[pla].[tblOsobaOrganizacijskaJedinica]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaOrganizacijskaJedinica_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaOrganizacijskaJedinica_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaOrganizacijskaJedinica_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsobaOrganizacijskaJedinica table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaOrganizacijskaJedinica_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOsoba int   = null ,

	@IDOrganizacijskaJedinica int   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOsoba]
	, [IDOrganizacijskaJedinica]
	, [DatumOd]
	, [DatumDo]
    FROM
	[pla].[tblOsobaOrganizacijskaJedinica]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([IDOrganizacijskaJedinica] = @IDOrganizacijskaJedinica OR @IDOrganizacijskaJedinica is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOsoba]
	, [IDOrganizacijskaJedinica]
	, [DatumOd]
	, [DatumDo]
    FROM
	[pla].[tblOsobaOrganizacijskaJedinica]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([IDOrganizacijskaJedinica] = @IDOrganizacijskaJedinica AND @IDOrganizacijskaJedinica is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaObustavaNaknada_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaObustavaNaknada_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaObustavaNaknada_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsobaObustavaNaknada table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaObustavaNaknada_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[OpisPlacanja],
					[ZiroRacun],
					[Iznos],
					[DanIsplateUMjesecu],
					[Model],
					[PozivNaBroj],
					[Napomena],
					[IDObustavaNaknadaTip],
					[IDOsoba],
					[PonavljanjeSvakihMjeseci],
					[PonavljajOdDatuma],
					[PonavljajDoDatuma]
				FROM
					[pla].[tblOsobaObustavaNaknada]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaObustavaNaknada_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaObustavaNaknada_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaObustavaNaknada_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsobaObustavaNaknada table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaObustavaNaknada_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [PrimateljNaziv]'
				SET @SQL = @SQL + ', [PrimateljSjediste]'
				SET @SQL = @SQL + ', [OpisPlacanja]'
				SET @SQL = @SQL + ', [ZiroRacun]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [DanIsplateUMjesecu]'
				SET @SQL = @SQL + ', [Model]'
				SET @SQL = @SQL + ', [PozivNaBroj]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [IDObustavaNaknadaTip]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [PonavljanjeSvakihMjeseci]'
				SET @SQL = @SQL + ', [PonavljajOdDatuma]'
				SET @SQL = @SQL + ', [PonavljajDoDatuma]'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaObustavaNaknada]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [PrimateljNaziv],'
				SET @SQL = @SQL + ' [PrimateljSjediste],'
				SET @SQL = @SQL + ' [OpisPlacanja],'
				SET @SQL = @SQL + ' [ZiroRacun],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [DanIsplateUMjesecu],'
				SET @SQL = @SQL + ' [Model],'
				SET @SQL = @SQL + ' [PozivNaBroj],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [IDObustavaNaknadaTip],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [PonavljanjeSvakihMjeseci],'
				SET @SQL = @SQL + ' [PonavljajOdDatuma],'
				SET @SQL = @SQL + ' [PonavljajDoDatuma]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaObustavaNaknada]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaObustavaNaknada_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaObustavaNaknada_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaObustavaNaknada_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsobaObustavaNaknada table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaObustavaNaknada_Insert
(

	@ID int    OUTPUT,

	@PrimateljNaziv nvarchar (50)  ,

	@PrimateljSjediste nvarchar (50)  ,

	@OpisPlacanja nvarchar (100)  ,

	@ZiroRacun nvarchar (20)  ,

	@Iznos money   ,

	@DanIsplateUMjesecu datetime   ,

	@Model nvarchar (2)  ,

	@PozivNaBroj nvarchar (23)  ,

	@Napomena nvarchar (100)  ,

	@IDObustavaNaknadaTip int   ,

	@IDOsoba int   ,

	@PonavljanjeSvakihMjeseci int   ,

	@PonavljajOdDatuma datetime   ,

	@PonavljajDoDatuma datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOsobaObustavaNaknada]
					(
					[PrimateljNaziv]
					,[PrimateljSjediste]
					,[OpisPlacanja]
					,[ZiroRacun]
					,[Iznos]
					,[DanIsplateUMjesecu]
					,[Model]
					,[PozivNaBroj]
					,[Napomena]
					,[IDObustavaNaknadaTip]
					,[IDOsoba]
					,[PonavljanjeSvakihMjeseci]
					,[PonavljajOdDatuma]
					,[PonavljajDoDatuma]
					)
				VALUES
					(
					@PrimateljNaziv
					,@PrimateljSjediste
					,@OpisPlacanja
					,@ZiroRacun
					,@Iznos
					,@DanIsplateUMjesecu
					,@Model
					,@PozivNaBroj
					,@Napomena
					,@IDObustavaNaknadaTip
					,@IDOsoba
					,@PonavljanjeSvakihMjeseci
					,@PonavljajOdDatuma
					,@PonavljajDoDatuma
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaObustavaNaknada_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaObustavaNaknada_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaObustavaNaknada_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsobaObustavaNaknada table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaObustavaNaknada_Update
(

	@ID int   ,

	@PrimateljNaziv nvarchar (50)  ,

	@PrimateljSjediste nvarchar (50)  ,

	@OpisPlacanja nvarchar (100)  ,

	@ZiroRacun nvarchar (20)  ,

	@Iznos money   ,

	@DanIsplateUMjesecu datetime   ,

	@Model nvarchar (2)  ,

	@PozivNaBroj nvarchar (23)  ,

	@Napomena nvarchar (100)  ,

	@IDObustavaNaknadaTip int   ,

	@IDOsoba int   ,

	@PonavljanjeSvakihMjeseci int   ,

	@PonavljajOdDatuma datetime   ,

	@PonavljajDoDatuma datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOsobaObustavaNaknada]
				SET
					[PrimateljNaziv] = @PrimateljNaziv
					,[PrimateljSjediste] = @PrimateljSjediste
					,[OpisPlacanja] = @OpisPlacanja
					,[ZiroRacun] = @ZiroRacun
					,[Iznos] = @Iznos
					,[DanIsplateUMjesecu] = @DanIsplateUMjesecu
					,[Model] = @Model
					,[PozivNaBroj] = @PozivNaBroj
					,[Napomena] = @Napomena
					,[IDObustavaNaknadaTip] = @IDObustavaNaknadaTip
					,[IDOsoba] = @IDOsoba
					,[PonavljanjeSvakihMjeseci] = @PonavljanjeSvakihMjeseci
					,[PonavljajOdDatuma] = @PonavljajOdDatuma
					,[PonavljajDoDatuma] = @PonavljajDoDatuma
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaObustavaNaknada_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaObustavaNaknada_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaObustavaNaknada_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsobaObustavaNaknada table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaObustavaNaknada_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOsobaObustavaNaknada] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaObustavaNaknada_GetByIDObustavaNaknadaTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaObustavaNaknada_GetByIDObustavaNaknadaTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaObustavaNaknada_GetByIDObustavaNaknadaTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaObustavaNaknada table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaObustavaNaknada_GetByIDObustavaNaknadaTip
(

	@IDObustavaNaknadaTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[OpisPlacanja],
					[ZiroRacun],
					[Iznos],
					[DanIsplateUMjesecu],
					[Model],
					[PozivNaBroj],
					[Napomena],
					[IDObustavaNaknadaTip],
					[IDOsoba],
					[PonavljanjeSvakihMjeseci],
					[PonavljajOdDatuma],
					[PonavljajDoDatuma]
				FROM
					[pla].[tblOsobaObustavaNaknada]
				WHERE
					[IDObustavaNaknadaTip] = @IDObustavaNaknadaTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaObustavaNaknada_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaObustavaNaknada_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaObustavaNaknada_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaObustavaNaknada table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaObustavaNaknada_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[OpisPlacanja],
					[ZiroRacun],
					[Iznos],
					[DanIsplateUMjesecu],
					[Model],
					[PozivNaBroj],
					[Napomena],
					[IDObustavaNaknadaTip],
					[IDOsoba],
					[PonavljanjeSvakihMjeseci],
					[PonavljajOdDatuma],
					[PonavljajDoDatuma]
				FROM
					[pla].[tblOsobaObustavaNaknada]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaObustavaNaknada_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaObustavaNaknada_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaObustavaNaknada_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaObustavaNaknada table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaObustavaNaknada_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[OpisPlacanja],
					[ZiroRacun],
					[Iznos],
					[DanIsplateUMjesecu],
					[Model],
					[PozivNaBroj],
					[Napomena],
					[IDObustavaNaknadaTip],
					[IDOsoba],
					[PonavljanjeSvakihMjeseci],
					[PonavljajOdDatuma],
					[PonavljajDoDatuma]
				FROM
					[pla].[tblOsobaObustavaNaknada]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaObustavaNaknada_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaObustavaNaknada_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaObustavaNaknada_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsobaObustavaNaknada table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaObustavaNaknada_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@PrimateljNaziv nvarchar (50)  = null ,

	@PrimateljSjediste nvarchar (50)  = null ,

	@OpisPlacanja nvarchar (100)  = null ,

	@ZiroRacun nvarchar (20)  = null ,

	@Iznos money   = null ,

	@DanIsplateUMjesecu datetime   = null ,

	@Model nvarchar (2)  = null ,

	@PozivNaBroj nvarchar (23)  = null ,

	@Napomena nvarchar (100)  = null ,

	@IDObustavaNaknadaTip int   = null ,

	@IDOsoba int   = null ,

	@PonavljanjeSvakihMjeseci int   = null ,

	@PonavljajOdDatuma datetime   = null ,

	@PonavljajDoDatuma datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [PrimateljNaziv]
	, [PrimateljSjediste]
	, [OpisPlacanja]
	, [ZiroRacun]
	, [Iznos]
	, [DanIsplateUMjesecu]
	, [Model]
	, [PozivNaBroj]
	, [Napomena]
	, [IDObustavaNaknadaTip]
	, [IDOsoba]
	, [PonavljanjeSvakihMjeseci]
	, [PonavljajOdDatuma]
	, [PonavljajDoDatuma]
    FROM
	[pla].[tblOsobaObustavaNaknada]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([PrimateljNaziv] = @PrimateljNaziv OR @PrimateljNaziv is null)
	AND ([PrimateljSjediste] = @PrimateljSjediste OR @PrimateljSjediste is null)
	AND ([OpisPlacanja] = @OpisPlacanja OR @OpisPlacanja is null)
	AND ([ZiroRacun] = @ZiroRacun OR @ZiroRacun is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
	AND ([DanIsplateUMjesecu] = @DanIsplateUMjesecu OR @DanIsplateUMjesecu is null)
	AND ([Model] = @Model OR @Model is null)
	AND ([PozivNaBroj] = @PozivNaBroj OR @PozivNaBroj is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([IDObustavaNaknadaTip] = @IDObustavaNaknadaTip OR @IDObustavaNaknadaTip is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([PonavljanjeSvakihMjeseci] = @PonavljanjeSvakihMjeseci OR @PonavljanjeSvakihMjeseci is null)
	AND ([PonavljajOdDatuma] = @PonavljajOdDatuma OR @PonavljajOdDatuma is null)
	AND ([PonavljajDoDatuma] = @PonavljajDoDatuma OR @PonavljajDoDatuma is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [PrimateljNaziv]
	, [PrimateljSjediste]
	, [OpisPlacanja]
	, [ZiroRacun]
	, [Iznos]
	, [DanIsplateUMjesecu]
	, [Model]
	, [PozivNaBroj]
	, [Napomena]
	, [IDObustavaNaknadaTip]
	, [IDOsoba]
	, [PonavljanjeSvakihMjeseci]
	, [PonavljajOdDatuma]
	, [PonavljajDoDatuma]
    FROM
	[pla].[tblOsobaObustavaNaknada]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([PrimateljNaziv] = @PrimateljNaziv AND @PrimateljNaziv is not null)
	OR ([PrimateljSjediste] = @PrimateljSjediste AND @PrimateljSjediste is not null)
	OR ([OpisPlacanja] = @OpisPlacanja AND @OpisPlacanja is not null)
	OR ([ZiroRacun] = @ZiroRacun AND @ZiroRacun is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	OR ([DanIsplateUMjesecu] = @DanIsplateUMjesecu AND @DanIsplateUMjesecu is not null)
	OR ([Model] = @Model AND @Model is not null)
	OR ([PozivNaBroj] = @PozivNaBroj AND @PozivNaBroj is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([IDObustavaNaknadaTip] = @IDObustavaNaknadaTip AND @IDObustavaNaknadaTip is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([PonavljanjeSvakihMjeseci] = @PonavljanjeSvakihMjeseci AND @PonavljanjeSvakihMjeseci is not null)
	OR ([PonavljajOdDatuma] = @PonavljajOdDatuma AND @PonavljajOdDatuma is not null)
	OR ([PonavljajDoDatuma] = @PonavljajDoDatuma AND @PonavljajDoDatuma is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPoreznaOlaksica_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPoreznaOlaksica_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPoreznaOlaksica_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsobaPoreznaOlaksica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPoreznaOlaksica_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[Datum],
					[Iznos],
					[Opis],
					[IDOsnovaOsiguranjaTip]
				FROM
					[pla].[tblOsobaPoreznaOlaksica]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPoreznaOlaksica_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPoreznaOlaksica_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPoreznaOlaksica_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsobaPoreznaOlaksica table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPoreznaOlaksica_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [IDOsnovaOsiguranjaTip]'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaPoreznaOlaksica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [IDOsnovaOsiguranjaTip]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaPoreznaOlaksica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPoreznaOlaksica_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPoreznaOlaksica_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPoreznaOlaksica_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsobaPoreznaOlaksica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPoreznaOlaksica_Insert
(

	@ID int    OUTPUT,

	@IDOsoba int   ,

	@Datum datetime   ,

	@Iznos money   ,

	@Opis nvarchar (200)  ,

	@IDOsnovaOsiguranjaTip int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOsobaPoreznaOlaksica]
					(
					[IDOsoba]
					,[Datum]
					,[Iznos]
					,[Opis]
					,[IDOsnovaOsiguranjaTip]
					)
				VALUES
					(
					@IDOsoba
					,@Datum
					,@Iznos
					,@Opis
					,@IDOsnovaOsiguranjaTip
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPoreznaOlaksica_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPoreznaOlaksica_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPoreznaOlaksica_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsobaPoreznaOlaksica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPoreznaOlaksica_Update
(

	@ID int   ,

	@IDOsoba int   ,

	@Datum datetime   ,

	@Iznos money   ,

	@Opis nvarchar (200)  ,

	@IDOsnovaOsiguranjaTip int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOsobaPoreznaOlaksica]
				SET
					[IDOsoba] = @IDOsoba
					,[Datum] = @Datum
					,[Iznos] = @Iznos
					,[Opis] = @Opis
					,[IDOsnovaOsiguranjaTip] = @IDOsnovaOsiguranjaTip
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPoreznaOlaksica_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPoreznaOlaksica_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPoreznaOlaksica_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsobaPoreznaOlaksica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPoreznaOlaksica_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOsobaPoreznaOlaksica] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPoreznaOlaksica_GetByIDOsnovaOsiguranjaTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPoreznaOlaksica_GetByIDOsnovaOsiguranjaTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPoreznaOlaksica_GetByIDOsnovaOsiguranjaTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaPoreznaOlaksica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPoreznaOlaksica_GetByIDOsnovaOsiguranjaTip
(

	@IDOsnovaOsiguranjaTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[Datum],
					[Iznos],
					[Opis],
					[IDOsnovaOsiguranjaTip]
				FROM
					[pla].[tblOsobaPoreznaOlaksica]
				WHERE
					[IDOsnovaOsiguranjaTip] = @IDOsnovaOsiguranjaTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPoreznaOlaksica_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPoreznaOlaksica_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPoreznaOlaksica_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaPoreznaOlaksica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPoreznaOlaksica_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[Datum],
					[Iznos],
					[Opis],
					[IDOsnovaOsiguranjaTip]
				FROM
					[pla].[tblOsobaPoreznaOlaksica]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPoreznaOlaksica_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPoreznaOlaksica_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPoreznaOlaksica_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaPoreznaOlaksica table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPoreznaOlaksica_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOsoba],
					[Datum],
					[Iznos],
					[Opis],
					[IDOsnovaOsiguranjaTip]
				FROM
					[pla].[tblOsobaPoreznaOlaksica]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaPoreznaOlaksica_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaPoreznaOlaksica_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaPoreznaOlaksica_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsobaPoreznaOlaksica table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaPoreznaOlaksica_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOsoba int   = null ,

	@Datum datetime   = null ,

	@Iznos money   = null ,

	@Opis nvarchar (200)  = null ,

	@IDOsnovaOsiguranjaTip int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOsoba]
	, [Datum]
	, [Iznos]
	, [Opis]
	, [IDOsnovaOsiguranjaTip]
    FROM
	[pla].[tblOsobaPoreznaOlaksica]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([Datum] = @Datum OR @Datum is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
	AND ([Opis] = @Opis OR @Opis is null)
	AND ([IDOsnovaOsiguranjaTip] = @IDOsnovaOsiguranjaTip OR @IDOsnovaOsiguranjaTip is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOsoba]
	, [Datum]
	, [Iznos]
	, [Opis]
	, [IDOsnovaOsiguranjaTip]
    FROM
	[pla].[tblOsobaPoreznaOlaksica]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([Datum] = @Datum AND @Datum is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	OR ([Opis] = @Opis AND @Opis is not null)
	OR ([IDOsnovaOsiguranjaTip] = @IDOsnovaOsiguranjaTip AND @IDOsnovaOsiguranjaTip is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaAdrese_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaAdrese_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaAdrese_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsobaAdrese table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaAdrese_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Adresa],
					[IDMjesto],
					[IDAdresaTip],
					[Napomena],
					[DatumOd],
					[DatumDo],
					[IDOsoba],
					[DodatakZaPrijevoz]
				FROM
					[pla].[tblOsobaAdrese]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaAdrese_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaAdrese_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaAdrese_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsobaAdrese table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaAdrese_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Adresa]'
				SET @SQL = @SQL + ', [IDMjesto]'
				SET @SQL = @SQL + ', [IDAdresaTip]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [DodatakZaPrijevoz]'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaAdrese]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Adresa],'
				SET @SQL = @SQL + ' [IDMjesto],'
				SET @SQL = @SQL + ' [IDAdresaTip],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [DodatakZaPrijevoz]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaAdrese]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaAdrese_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaAdrese_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaAdrese_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsobaAdrese table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaAdrese_Insert
(

	@ID int    OUTPUT,

	@Adresa nvarchar (300)  ,

	@IDMjesto int   ,

	@IDAdresaTip int   ,

	@Napomena nvarchar (300)  ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@IDOsoba int   ,

	@DodatakZaPrijevoz money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOsobaAdrese]
					(
					[Adresa]
					,[IDMjesto]
					,[IDAdresaTip]
					,[Napomena]
					,[DatumOd]
					,[DatumDo]
					,[IDOsoba]
					,[DodatakZaPrijevoz]
					)
				VALUES
					(
					@Adresa
					,@IDMjesto
					,@IDAdresaTip
					,@Napomena
					,@DatumOd
					,@DatumDo
					,@IDOsoba
					,@DodatakZaPrijevoz
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaAdrese_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaAdrese_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaAdrese_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsobaAdrese table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaAdrese_Update
(

	@ID int   ,

	@Adresa nvarchar (300)  ,

	@IDMjesto int   ,

	@IDAdresaTip int   ,

	@Napomena nvarchar (300)  ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@IDOsoba int   ,

	@DodatakZaPrijevoz money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOsobaAdrese]
				SET
					[Adresa] = @Adresa
					,[IDMjesto] = @IDMjesto
					,[IDAdresaTip] = @IDAdresaTip
					,[Napomena] = @Napomena
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[IDOsoba] = @IDOsoba
					,[DodatakZaPrijevoz] = @DodatakZaPrijevoz
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaAdrese_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaAdrese_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaAdrese_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsobaAdrese table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaAdrese_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOsobaAdrese] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaAdrese_GetByIDAdresaTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaAdrese_GetByIDAdresaTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaAdrese_GetByIDAdresaTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaAdrese table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaAdrese_GetByIDAdresaTip
(

	@IDAdresaTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Adresa],
					[IDMjesto],
					[IDAdresaTip],
					[Napomena],
					[DatumOd],
					[DatumDo],
					[IDOsoba],
					[DodatakZaPrijevoz]
				FROM
					[pla].[tblOsobaAdrese]
				WHERE
					[IDAdresaTip] = @IDAdresaTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaAdrese_GetByIDMjesto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaAdrese_GetByIDMjesto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaAdrese_GetByIDMjesto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaAdrese table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaAdrese_GetByIDMjesto
(

	@IDMjesto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Adresa],
					[IDMjesto],
					[IDAdresaTip],
					[Napomena],
					[DatumOd],
					[DatumDo],
					[IDOsoba],
					[DodatakZaPrijevoz]
				FROM
					[pla].[tblOsobaAdrese]
				WHERE
					[IDMjesto] = @IDMjesto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaAdrese_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaAdrese_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaAdrese_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaAdrese table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaAdrese_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Adresa],
					[IDMjesto],
					[IDAdresaTip],
					[Napomena],
					[DatumOd],
					[DatumDo],
					[IDOsoba],
					[DodatakZaPrijevoz]
				FROM
					[pla].[tblOsobaAdrese]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaAdrese_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaAdrese_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaAdrese_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaAdrese table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaAdrese_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Adresa],
					[IDMjesto],
					[IDAdresaTip],
					[Napomena],
					[DatumOd],
					[DatumDo],
					[IDOsoba],
					[DodatakZaPrijevoz]
				FROM
					[pla].[tblOsobaAdrese]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaAdrese_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaAdrese_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaAdrese_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsobaAdrese table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaAdrese_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Adresa nvarchar (300)  = null ,

	@IDMjesto int   = null ,

	@IDAdresaTip int   = null ,

	@Napomena nvarchar (300)  = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@IDOsoba int   = null ,

	@DodatakZaPrijevoz money   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Adresa]
	, [IDMjesto]
	, [IDAdresaTip]
	, [Napomena]
	, [DatumOd]
	, [DatumDo]
	, [IDOsoba]
	, [DodatakZaPrijevoz]
    FROM
	[pla].[tblOsobaAdrese]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Adresa] = @Adresa OR @Adresa is null)
	AND ([IDMjesto] = @IDMjesto OR @IDMjesto is null)
	AND ([IDAdresaTip] = @IDAdresaTip OR @IDAdresaTip is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([DodatakZaPrijevoz] = @DodatakZaPrijevoz OR @DodatakZaPrijevoz is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Adresa]
	, [IDMjesto]
	, [IDAdresaTip]
	, [Napomena]
	, [DatumOd]
	, [DatumDo]
	, [IDOsoba]
	, [DodatakZaPrijevoz]
    FROM
	[pla].[tblOsobaAdrese]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Adresa] = @Adresa AND @Adresa is not null)
	OR ([IDMjesto] = @IDMjesto AND @IDMjesto is not null)
	OR ([IDAdresaTip] = @IDAdresaTip AND @IDAdresaTip is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([DodatakZaPrijevoz] = @DodatakZaPrijevoz AND @DodatakZaPrijevoz is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeRobnog_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeRobnog_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeRobnog_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tbl_PostavkeRobnog table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeRobnog_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[RobnoPozivNaBr],
					[RobnoModel]
				FROM
					[dbo].[tbl_PostavkeRobnog]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeRobnog_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeRobnog_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeRobnog_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tbl_PostavkeRobnog table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeRobnog_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [RobnoPozivNaBr]'
				SET @SQL = @SQL + ', [RobnoModel]'
				SET @SQL = @SQL + ' FROM [dbo].[tbl_PostavkeRobnog]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [RobnoPozivNaBr],'
				SET @SQL = @SQL + ' [RobnoModel]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tbl_PostavkeRobnog]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeRobnog_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeRobnog_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeRobnog_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tbl_PostavkeRobnog table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeRobnog_Insert
(

	@ID int   ,

	@RobnoPozivNaBr varchar (100)  ,

	@RobnoModel varchar (2)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tbl_PostavkeRobnog]
					(
					[ID]
					,[RobnoPozivNaBr]
					,[RobnoModel]
					)
				VALUES
					(
					@ID
					,@RobnoPozivNaBr
					,@RobnoModel
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeRobnog_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeRobnog_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeRobnog_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tbl_PostavkeRobnog table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeRobnog_Update
(

	@ID int   ,

	@OriginalID int   ,

	@RobnoPozivNaBr varchar (100)  ,

	@RobnoModel varchar (2)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tbl_PostavkeRobnog]
				SET
					[ID] = @ID
					,[RobnoPozivNaBr] = @RobnoPozivNaBr
					,[RobnoModel] = @RobnoModel
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeRobnog_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeRobnog_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeRobnog_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tbl_PostavkeRobnog table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeRobnog_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tbl_PostavkeRobnog] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeRobnog_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeRobnog_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeRobnog_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tbl_PostavkeRobnog table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeRobnog_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[RobnoPozivNaBr],
					[RobnoModel]
				FROM
					[dbo].[tbl_PostavkeRobnog]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeRobnog_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeRobnog_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeRobnog_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tbl_PostavkeRobnog table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeRobnog_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@RobnoPozivNaBr varchar (100)  = null ,

	@RobnoModel varchar (2)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [RobnoPozivNaBr]
	, [RobnoModel]
    FROM
	[dbo].[tbl_PostavkeRobnog]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([RobnoPozivNaBr] = @RobnoPozivNaBr OR @RobnoPozivNaBr is null)
	AND ([RobnoModel] = @RobnoModel OR @RobnoModel is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [RobnoPozivNaBr]
	, [RobnoModel]
    FROM
	[dbo].[tbl_PostavkeRobnog]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([RobnoPozivNaBr] = @RobnoPozivNaBr AND @RobnoPozivNaBr is not null)
	OR ([RobnoModel] = @RobnoModel AND @RobnoModel is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadniOdnos_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadniOdnos_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadniOdnos_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsobaRadniOdnos table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadniOdnos_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDRadniOdnosTip],
					[IDOsoba],
					[DatumOd],
					[DatumDo],
					[Napomena],
					[IzvanOrganizacije],
					[NazivVanjskeOrganizacije],
					[DnevniBrojRadnihSati],
					[SubotaRadna],
					[StazMjeseci1],
					[StazMjeseci2]
				FROM
					[pla].[tblOsobaRadniOdnos]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadniOdnos_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadniOdnos_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadniOdnos_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsobaRadniOdnos table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadniOdnos_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDRadniOdnosTip]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [IzvanOrganizacije]'
				SET @SQL = @SQL + ', [NazivVanjskeOrganizacije]'
				SET @SQL = @SQL + ', [DnevniBrojRadnihSati]'
				SET @SQL = @SQL + ', [SubotaRadna]'
				SET @SQL = @SQL + ', [StazMjeseci1]'
				SET @SQL = @SQL + ', [StazMjeseci2]'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaRadniOdnos]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDRadniOdnosTip],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [IzvanOrganizacije],'
				SET @SQL = @SQL + ' [NazivVanjskeOrganizacije],'
				SET @SQL = @SQL + ' [DnevniBrojRadnihSati],'
				SET @SQL = @SQL + ' [SubotaRadna],'
				SET @SQL = @SQL + ' [StazMjeseci1],'
				SET @SQL = @SQL + ' [StazMjeseci2]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaRadniOdnos]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadniOdnos_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadniOdnos_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadniOdnos_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsobaRadniOdnos table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadniOdnos_Insert
(

	@ID int    OUTPUT,

	@IDRadniOdnosTip int   ,

	@IDOsoba int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@Napomena nvarchar (300)  ,

	@IzvanOrganizacije bit   ,

	@NazivVanjskeOrganizacije nvarchar (200)  ,

	@DnevniBrojRadnihSati int   ,

	@SubotaRadna bit   ,

	@StazMjeseci1 int   ,

	@StazMjeseci2 int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOsobaRadniOdnos]
					(
					[IDRadniOdnosTip]
					,[IDOsoba]
					,[DatumOd]
					,[DatumDo]
					,[Napomena]
					,[IzvanOrganizacije]
					,[NazivVanjskeOrganizacije]
					,[DnevniBrojRadnihSati]
					,[SubotaRadna]
					,[StazMjeseci1]
					,[StazMjeseci2]
					)
				VALUES
					(
					@IDRadniOdnosTip
					,@IDOsoba
					,@DatumOd
					,@DatumDo
					,@Napomena
					,@IzvanOrganizacije
					,@NazivVanjskeOrganizacije
					,@DnevniBrojRadnihSati
					,@SubotaRadna
					,@StazMjeseci1
					,@StazMjeseci2
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadniOdnos_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadniOdnos_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadniOdnos_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsobaRadniOdnos table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadniOdnos_Update
(

	@ID int   ,

	@IDRadniOdnosTip int   ,

	@IDOsoba int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@Napomena nvarchar (300)  ,

	@IzvanOrganizacije bit   ,

	@NazivVanjskeOrganizacije nvarchar (200)  ,

	@DnevniBrojRadnihSati int   ,

	@SubotaRadna bit   ,

	@StazMjeseci1 int   ,

	@StazMjeseci2 int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOsobaRadniOdnos]
				SET
					[IDRadniOdnosTip] = @IDRadniOdnosTip
					,[IDOsoba] = @IDOsoba
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[Napomena] = @Napomena
					,[IzvanOrganizacije] = @IzvanOrganizacije
					,[NazivVanjskeOrganizacije] = @NazivVanjskeOrganizacije
					,[DnevniBrojRadnihSati] = @DnevniBrojRadnihSati
					,[SubotaRadna] = @SubotaRadna
					,[StazMjeseci1] = @StazMjeseci1
					,[StazMjeseci2] = @StazMjeseci2
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadniOdnos_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadniOdnos_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadniOdnos_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsobaRadniOdnos table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadniOdnos_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOsobaRadniOdnos] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadniOdnos_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadniOdnos_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadniOdnos_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaRadniOdnos table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadniOdnos_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDRadniOdnosTip],
					[IDOsoba],
					[DatumOd],
					[DatumDo],
					[Napomena],
					[IzvanOrganizacije],
					[NazivVanjskeOrganizacije],
					[DnevniBrojRadnihSati],
					[SubotaRadna],
					[StazMjeseci1],
					[StazMjeseci2]
				FROM
					[pla].[tblOsobaRadniOdnos]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadniOdnos_GetByIDRadniOdnosTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadniOdnos_GetByIDRadniOdnosTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadniOdnos_GetByIDRadniOdnosTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaRadniOdnos table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadniOdnos_GetByIDRadniOdnosTip
(

	@IDRadniOdnosTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDRadniOdnosTip],
					[IDOsoba],
					[DatumOd],
					[DatumDo],
					[Napomena],
					[IzvanOrganizacije],
					[NazivVanjskeOrganizacije],
					[DnevniBrojRadnihSati],
					[SubotaRadna],
					[StazMjeseci1],
					[StazMjeseci2]
				FROM
					[pla].[tblOsobaRadniOdnos]
				WHERE
					[IDRadniOdnosTip] = @IDRadniOdnosTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadniOdnos_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadniOdnos_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadniOdnos_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaRadniOdnos table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadniOdnos_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDRadniOdnosTip],
					[IDOsoba],
					[DatumOd],
					[DatumDo],
					[Napomena],
					[IzvanOrganizacije],
					[NazivVanjskeOrganizacije],
					[DnevniBrojRadnihSati],
					[SubotaRadna],
					[StazMjeseci1],
					[StazMjeseci2]
				FROM
					[pla].[tblOsobaRadniOdnos]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadniOdnos_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadniOdnos_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadniOdnos_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsobaRadniOdnos table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadniOdnos_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDRadniOdnosTip int   = null ,

	@IDOsoba int   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@Napomena nvarchar (300)  = null ,

	@IzvanOrganizacije bit   = null ,

	@NazivVanjskeOrganizacije nvarchar (200)  = null ,

	@DnevniBrojRadnihSati int   = null ,

	@SubotaRadna bit   = null ,

	@StazMjeseci1 int   = null ,

	@StazMjeseci2 int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDRadniOdnosTip]
	, [IDOsoba]
	, [DatumOd]
	, [DatumDo]
	, [Napomena]
	, [IzvanOrganizacije]
	, [NazivVanjskeOrganizacije]
	, [DnevniBrojRadnihSati]
	, [SubotaRadna]
	, [StazMjeseci1]
	, [StazMjeseci2]
    FROM
	[pla].[tblOsobaRadniOdnos]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDRadniOdnosTip] = @IDRadniOdnosTip OR @IDRadniOdnosTip is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([IzvanOrganizacije] = @IzvanOrganizacije OR @IzvanOrganizacije is null)
	AND ([NazivVanjskeOrganizacije] = @NazivVanjskeOrganizacije OR @NazivVanjskeOrganizacije is null)
	AND ([DnevniBrojRadnihSati] = @DnevniBrojRadnihSati OR @DnevniBrojRadnihSati is null)
	AND ([SubotaRadna] = @SubotaRadna OR @SubotaRadna is null)
	AND ([StazMjeseci1] = @StazMjeseci1 OR @StazMjeseci1 is null)
	AND ([StazMjeseci2] = @StazMjeseci2 OR @StazMjeseci2 is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDRadniOdnosTip]
	, [IDOsoba]
	, [DatumOd]
	, [DatumDo]
	, [Napomena]
	, [IzvanOrganizacije]
	, [NazivVanjskeOrganizacije]
	, [DnevniBrojRadnihSati]
	, [SubotaRadna]
	, [StazMjeseci1]
	, [StazMjeseci2]
    FROM
	[pla].[tblOsobaRadniOdnos]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDRadniOdnosTip] = @IDRadniOdnosTip AND @IDRadniOdnosTip is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([IzvanOrganizacije] = @IzvanOrganizacije AND @IzvanOrganizacije is not null)
	OR ([NazivVanjskeOrganizacije] = @NazivVanjskeOrganizacije AND @NazivVanjskeOrganizacije is not null)
	OR ([DnevniBrojRadnihSati] = @DnevniBrojRadnihSati AND @DnevniBrojRadnihSati is not null)
	OR ([SubotaRadna] = @SubotaRadna AND @SubotaRadna is not null)
	OR ([StazMjeseci1] = @StazMjeseci1 AND @StazMjeseci1 is not null)
	OR ([StazMjeseci2] = @StazMjeseci2 AND @StazMjeseci2 is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadnoMjesto_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadnoMjesto_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadnoMjesto_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsobaRadnoMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadnoMjesto_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[IDRadnoMjesto],
					[DatumOd],
					[DatumDo],
					[PotrebnoUtvrdivanjeRadneSposobnosti]
				FROM
					[pla].[tblOsobaRadnoMjesto]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadnoMjesto_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadnoMjesto_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadnoMjesto_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsobaRadnoMjesto table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadnoMjesto_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [IDRadnoMjesto]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [PotrebnoUtvrdivanjeRadneSposobnosti]'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaRadnoMjesto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [IDRadnoMjesto],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [PotrebnoUtvrdivanjeRadneSposobnosti]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOsobaRadnoMjesto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadnoMjesto_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadnoMjesto_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadnoMjesto_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsobaRadnoMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadnoMjesto_Insert
(

	@ID int    OUTPUT,

	@IDOsoba int   ,

	@IDRadnoMjesto int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@PotrebnoUtvrdivanjeRadneSposobnosti int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOsobaRadnoMjesto]
					(
					[IDOsoba]
					,[IDRadnoMjesto]
					,[DatumOd]
					,[DatumDo]
					,[PotrebnoUtvrdivanjeRadneSposobnosti]
					)
				VALUES
					(
					@IDOsoba
					,@IDRadnoMjesto
					,@DatumOd
					,@DatumDo
					,@PotrebnoUtvrdivanjeRadneSposobnosti
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadnoMjesto_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadnoMjesto_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadnoMjesto_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsobaRadnoMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadnoMjesto_Update
(

	@ID int   ,

	@IDOsoba int   ,

	@IDRadnoMjesto int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@PotrebnoUtvrdivanjeRadneSposobnosti int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOsobaRadnoMjesto]
				SET
					[IDOsoba] = @IDOsoba
					,[IDRadnoMjesto] = @IDRadnoMjesto
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[PotrebnoUtvrdivanjeRadneSposobnosti] = @PotrebnoUtvrdivanjeRadneSposobnosti
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadnoMjesto_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadnoMjesto_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadnoMjesto_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsobaRadnoMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadnoMjesto_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOsobaRadnoMjesto] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadnoMjesto_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadnoMjesto_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadnoMjesto_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaRadnoMjesto table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadnoMjesto_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[IDRadnoMjesto],
					[DatumOd],
					[DatumDo],
					[PotrebnoUtvrdivanjeRadneSposobnosti]
				FROM
					[pla].[tblOsobaRadnoMjesto]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadnoMjesto_GetByIDRadnoMjesto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadnoMjesto_GetByIDRadnoMjesto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadnoMjesto_GetByIDRadnoMjesto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaRadnoMjesto table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadnoMjesto_GetByIDRadnoMjesto
(

	@IDRadnoMjesto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[IDRadnoMjesto],
					[DatumOd],
					[DatumDo],
					[PotrebnoUtvrdivanjeRadneSposobnosti]
				FROM
					[pla].[tblOsobaRadnoMjesto]
				WHERE
					[IDRadnoMjesto] = @IDRadnoMjesto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadnoMjesto_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadnoMjesto_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadnoMjesto_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsobaRadnoMjesto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadnoMjesto_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOsoba],
					[IDRadnoMjesto],
					[DatumOd],
					[DatumDo],
					[PotrebnoUtvrdivanjeRadneSposobnosti]
				FROM
					[pla].[tblOsobaRadnoMjesto]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsobaRadnoMjesto_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsobaRadnoMjesto_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsobaRadnoMjesto_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsobaRadnoMjesto table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsobaRadnoMjesto_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOsoba int   = null ,

	@IDRadnoMjesto int   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@PotrebnoUtvrdivanjeRadneSposobnosti int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOsoba]
	, [IDRadnoMjesto]
	, [DatumOd]
	, [DatumDo]
	, [PotrebnoUtvrdivanjeRadneSposobnosti]
    FROM
	[pla].[tblOsobaRadnoMjesto]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([IDRadnoMjesto] = @IDRadnoMjesto OR @IDRadnoMjesto is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([PotrebnoUtvrdivanjeRadneSposobnosti] = @PotrebnoUtvrdivanjeRadneSposobnosti OR @PotrebnoUtvrdivanjeRadneSposobnosti is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOsoba]
	, [IDRadnoMjesto]
	, [DatumOd]
	, [DatumDo]
	, [PotrebnoUtvrdivanjeRadneSposobnosti]
    FROM
	[pla].[tblOsobaRadnoMjesto]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([IDRadnoMjesto] = @IDRadnoMjesto AND @IDRadnoMjesto is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([PotrebnoUtvrdivanjeRadneSposobnosti] = @PotrebnoUtvrdivanjeRadneSposobnosti AND @PotrebnoUtvrdivanjeRadneSposobnosti is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPrilagodenDokumentTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPrilagodenDokumentTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPrilagodenDokumentTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblPrilagodenDokumentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPrilagodenDokumentTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDDokumentTip],
					[Naziv],
					[SkraceniNaziv],
					[Parametar1],
					[Parametar2],
					[Parametar3]
				FROM
					[dbo].[tblPrilagodenDokumentTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPrilagodenDokumentTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPrilagodenDokumentTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPrilagodenDokumentTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblPrilagodenDokumentTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPrilagodenDokumentTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDDokumentTip]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDDokumentTip]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [SkraceniNaziv]'
				SET @SQL = @SQL + ', [Parametar1]'
				SET @SQL = @SQL + ', [Parametar2]'
				SET @SQL = @SQL + ', [Parametar3]'
				SET @SQL = @SQL + ' FROM [dbo].[tblPrilagodenDokumentTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDDokumentTip],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [SkraceniNaziv],'
				SET @SQL = @SQL + ' [Parametar1],'
				SET @SQL = @SQL + ' [Parametar2],'
				SET @SQL = @SQL + ' [Parametar3]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblPrilagodenDokumentTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPrilagodenDokumentTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPrilagodenDokumentTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPrilagodenDokumentTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblPrilagodenDokumentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPrilagodenDokumentTip_Insert
(

	@IDDokumentTip int   ,

	@Naziv nvarchar (200)  ,

	@SkraceniNaziv nvarchar (10)  ,

	@Parametar1 nvarchar (400)  ,

	@Parametar2 nvarchar (400)  ,

	@Parametar3 nvarchar (400)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblPrilagodenDokumentTip]
					(
					[IDDokumentTip]
					,[Naziv]
					,[SkraceniNaziv]
					,[Parametar1]
					,[Parametar2]
					,[Parametar3]
					)
				VALUES
					(
					@IDDokumentTip
					,@Naziv
					,@SkraceniNaziv
					,@Parametar1
					,@Parametar2
					,@Parametar3
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPrilagodenDokumentTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPrilagodenDokumentTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPrilagodenDokumentTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblPrilagodenDokumentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPrilagodenDokumentTip_Update
(

	@IDDokumentTip int   ,

	@OriginalIDDokumentTip int   ,

	@Naziv nvarchar (200)  ,

	@SkraceniNaziv nvarchar (10)  ,

	@Parametar1 nvarchar (400)  ,

	@Parametar2 nvarchar (400)  ,

	@Parametar3 nvarchar (400)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblPrilagodenDokumentTip]
				SET
					[IDDokumentTip] = @IDDokumentTip
					,[Naziv] = @Naziv
					,[SkraceniNaziv] = @SkraceniNaziv
					,[Parametar1] = @Parametar1
					,[Parametar2] = @Parametar2
					,[Parametar3] = @Parametar3
				WHERE
[IDDokumentTip] = @OriginalIDDokumentTip 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPrilagodenDokumentTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPrilagodenDokumentTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPrilagodenDokumentTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblPrilagodenDokumentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPrilagodenDokumentTip_Delete
(

	@IDDokumentTip int   
)
AS


				DELETE FROM [dbo].[tblPrilagodenDokumentTip] WITH (ROWLOCK) 
				WHERE
					[IDDokumentTip] = @IDDokumentTip
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPrilagodenDokumentTip_GetByIDDokumentTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPrilagodenDokumentTip_GetByIDDokumentTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPrilagodenDokumentTip_GetByIDDokumentTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPrilagodenDokumentTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPrilagodenDokumentTip_GetByIDDokumentTip
(

	@IDDokumentTip int   
)
AS


				SELECT
					[IDDokumentTip],
					[Naziv],
					[SkraceniNaziv],
					[Parametar1],
					[Parametar2],
					[Parametar3]
				FROM
					[dbo].[tblPrilagodenDokumentTip]
				WHERE
					[IDDokumentTip] = @IDDokumentTip
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPrilagodenDokumentTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPrilagodenDokumentTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPrilagodenDokumentTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblPrilagodenDokumentTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPrilagodenDokumentTip_Find
(

	@SearchUsingOR bit   = null ,

	@IDDokumentTip int   = null ,

	@Naziv nvarchar (200)  = null ,

	@SkraceniNaziv nvarchar (10)  = null ,

	@Parametar1 nvarchar (400)  = null ,

	@Parametar2 nvarchar (400)  = null ,

	@Parametar3 nvarchar (400)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [IDDokumentTip]
	, [Naziv]
	, [SkraceniNaziv]
	, [Parametar1]
	, [Parametar2]
	, [Parametar3]
    FROM
	[dbo].[tblPrilagodenDokumentTip]
    WHERE 
	 ([IDDokumentTip] = @IDDokumentTip OR @IDDokumentTip is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([SkraceniNaziv] = @SkraceniNaziv OR @SkraceniNaziv is null)
	AND ([Parametar1] = @Parametar1 OR @Parametar1 is null)
	AND ([Parametar2] = @Parametar2 OR @Parametar2 is null)
	AND ([Parametar3] = @Parametar3 OR @Parametar3 is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [IDDokumentTip]
	, [Naziv]
	, [SkraceniNaziv]
	, [Parametar1]
	, [Parametar2]
	, [Parametar3]
    FROM
	[dbo].[tblPrilagodenDokumentTip]
    WHERE 
	 ([IDDokumentTip] = @IDDokumentTip AND @IDDokumentTip is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([SkraceniNaziv] = @SkraceniNaziv AND @SkraceniNaziv is not null)
	OR ([Parametar1] = @Parametar1 AND @Parametar1 is not null)
	OR ([Parametar2] = @Parametar2 AND @Parametar2 is not null)
	OR ([Parametar3] = @Parametar3 AND @Parametar3 is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPorez_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPorez_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPorez_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblPorez table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPorez_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[StopaPoreza],
					[PreracunataStopa]
				FROM
					[dbo].[tblPorez]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPorez_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPorez_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPorez_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblPorez table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPorez_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [StopaPoreza]'
				SET @SQL = @SQL + ', [PreracunataStopa]'
				SET @SQL = @SQL + ' FROM [dbo].[tblPorez]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [StopaPoreza],'
				SET @SQL = @SQL + ' [PreracunataStopa]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblPorez]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPorez_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPorez_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPorez_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblPorez table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPorez_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  ,

	@StopaPoreza real   ,

	@PreracunataStopa real    OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblPorez]
					(
					[Naziv]
					,[StopaPoreza]
					)
				VALUES
					(
					@Naziv
					,@StopaPoreza
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
				-- Select computed columns into output parameters
				SELECT
 @PreracunataStopa = [PreracunataStopa]
				FROM
					[dbo].[tblPorez]
				WHERE
[ID] = @ID 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPorez_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPorez_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPorez_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblPorez table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPorez_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  ,

	@StopaPoreza real   ,

	@PreracunataStopa real    OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblPorez]
				SET
					[Naziv] = @Naziv
					,[StopaPoreza] = @StopaPoreza
				WHERE
[ID] = @ID 
				
				
				-- Select computed columns into output parameters
				SELECT
 @PreracunataStopa = [PreracunataStopa]
				FROM
					[dbo].[tblPorez]
				WHERE
[ID] = @ID 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPorez_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPorez_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPorez_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblPorez table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPorez_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblPorez] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPorez_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPorez_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPorez_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPorez table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPorez_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[StopaPoreza],
					[PreracunataStopa]
				FROM
					[dbo].[tblPorez]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblPorez_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblPorez_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblPorez_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblPorez table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblPorez_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null ,

	@StopaPoreza real   = null ,

	@PreracunataStopa real   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [StopaPoreza]
	, [PreracunataStopa]
    FROM
	[dbo].[tblPorez]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([StopaPoreza] = @StopaPoreza OR @StopaPoreza is null)
	AND ([PreracunataStopa] = @PreracunataStopa OR @PreracunataStopa is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [StopaPoreza]
	, [PreracunataStopa]
    FROM
	[dbo].[tblPorez]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([StopaPoreza] = @StopaPoreza AND @StopaPoreza is not null)
	OR ([PreracunataStopa] = @PreracunataStopa AND @PreracunataStopa is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametriNazivi_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametriNazivi_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametriNazivi_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblParametriNazivi table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametriNazivi_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[Param],
					[Vrijednost],
					[Naziv],
					[Opis]
				FROM
					[dbo].[tblParametriNazivi]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametriNazivi_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametriNazivi_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametriNazivi_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblParametriNazivi table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametriNazivi_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Param]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Param]'
				SET @SQL = @SQL + ', [Vrijednost]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ' FROM [dbo].[tblParametriNazivi]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Param],'
				SET @SQL = @SQL + ' [Vrijednost],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Opis]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblParametriNazivi]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametriNazivi_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametriNazivi_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametriNazivi_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblParametriNazivi table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametriNazivi_Insert
(

	@Param varchar (30)  ,

	@Vrijednost varchar (15)  ,

	@Naziv nvarchar (50)  ,

	@Opis nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblParametriNazivi]
					(
					[Param]
					,[Vrijednost]
					,[Naziv]
					,[Opis]
					)
				VALUES
					(
					@Param
					,@Vrijednost
					,@Naziv
					,@Opis
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametriNazivi_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametriNazivi_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametriNazivi_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblParametriNazivi table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametriNazivi_Update
(

	@Param varchar (30)  ,

	@OriginalParam varchar (30)  ,

	@Vrijednost varchar (15)  ,

	@Naziv nvarchar (50)  ,

	@Opis nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblParametriNazivi]
				SET
					[Param] = @Param
					,[Vrijednost] = @Vrijednost
					,[Naziv] = @Naziv
					,[Opis] = @Opis
				WHERE
[Param] = @OriginalParam 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametriNazivi_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametriNazivi_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametriNazivi_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblParametriNazivi table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametriNazivi_Delete
(

	@Param varchar (30)  
)
AS


				DELETE FROM [dbo].[tblParametriNazivi] WITH (ROWLOCK) 
				WHERE
					[Param] = @Param
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametriNazivi_GetByParam procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametriNazivi_GetByParam') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametriNazivi_GetByParam
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblParametriNazivi table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametriNazivi_GetByParam
(

	@Param varchar (30)  
)
AS


				SELECT
					[Param],
					[Vrijednost],
					[Naziv],
					[Opis]
				FROM
					[dbo].[tblParametriNazivi]
				WHERE
					[Param] = @Param
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametriNazivi_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametriNazivi_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametriNazivi_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblParametriNazivi table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametriNazivi_Find
(

	@SearchUsingOR bit   = null ,

	@Param varchar (30)  = null ,

	@Vrijednost varchar (15)  = null ,

	@Naziv nvarchar (50)  = null ,

	@Opis nvarchar (100)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Param]
	, [Vrijednost]
	, [Naziv]
	, [Opis]
    FROM
	[dbo].[tblParametriNazivi]
    WHERE 
	 ([Param] = @Param OR @Param is null)
	AND ([Vrijednost] = @Vrijednost OR @Vrijednost is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Opis] = @Opis OR @Opis is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Param]
	, [Vrijednost]
	, [Naziv]
	, [Opis]
    FROM
	[dbo].[tblParametriNazivi]
    WHERE 
	 ([Param] = @Param AND @Param is not null)
	OR ([Vrijednost] = @Vrijednost AND @Vrijednost is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Opis] = @Opis AND @Opis is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametri_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametri_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametri_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblParametri table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametri_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDGrupaParametra],
					[Param],
					[Vrijednost],
					[ID]
				FROM
					[dbo].[tblParametri]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametri_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametri_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametri_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblParametri table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametri_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDGrupaParametra]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDGrupaParametra]'
				SET @SQL = @SQL + ', [Param]'
				SET @SQL = @SQL + ', [Vrijednost]'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ' FROM [dbo].[tblParametri]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDGrupaParametra],'
				SET @SQL = @SQL + ' [Param],'
				SET @SQL = @SQL + ' [Vrijednost],'
				SET @SQL = @SQL + ' [ID]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblParametri]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametri_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametri_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametri_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblParametri table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametri_Insert
(

	@IDGrupaParametra int   ,

	@Param varchar (30)  ,

	@Vrijednost varchar (15)  ,

	@ID int    OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblParametri]
					(
					[IDGrupaParametra]
					,[Param]
					,[Vrijednost]
					)
				VALUES
					(
					@IDGrupaParametra
					,@Param
					,@Vrijednost
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametri_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametri_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametri_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblParametri table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametri_Update
(

	@IDGrupaParametra int   ,

	@Param varchar (30)  ,

	@Vrijednost varchar (15)  ,

	@ID int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblParametri]
				SET
					[IDGrupaParametra] = @IDGrupaParametra
					,[Param] = @Param
					,[Vrijednost] = @Vrijednost
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametri_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametri_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametri_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblParametri table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametri_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblParametri] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametri_GetByIDGrupaParametra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametri_GetByIDGrupaParametra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametri_GetByIDGrupaParametra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblParametri table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametri_GetByIDGrupaParametra
(

	@IDGrupaParametra int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDGrupaParametra],
					[Param],
					[Vrijednost],
					[ID]
				FROM
					[dbo].[tblParametri]
				WHERE
					[IDGrupaParametra] = @IDGrupaParametra
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametri_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametri_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametri_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblParametri table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametri_GetByID
(

	@ID int   
)
AS


				SELECT
					[IDGrupaParametra],
					[Param],
					[Vrijednost],
					[ID]
				FROM
					[dbo].[tblParametri]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblParametri_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblParametri_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblParametri_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblParametri table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblParametri_Find
(

	@SearchUsingOR bit   = null ,

	@IDGrupaParametra int   = null ,

	@Param varchar (30)  = null ,

	@Vrijednost varchar (15)  = null ,

	@ID int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [IDGrupaParametra]
	, [Param]
	, [Vrijednost]
	, [ID]
    FROM
	[dbo].[tblParametri]
    WHERE 
	 ([IDGrupaParametra] = @IDGrupaParametra OR @IDGrupaParametra is null)
	AND ([Param] = @Param OR @Param is null)
	AND ([Vrijednost] = @Vrijednost OR @Vrijednost is null)
	AND ([ID] = @ID OR @ID is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [IDGrupaParametra]
	, [Param]
	, [Vrijednost]
	, [ID]
    FROM
	[dbo].[tblParametri]
    WHERE 
	 ([IDGrupaParametra] = @IDGrupaParametra AND @IDGrupaParametra is not null)
	OR ([Param] = @Param AND @Param is not null)
	OR ([Vrijednost] = @Vrijednost AND @Vrijednost is not null)
	OR ([ID] = @ID AND @ID is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSTipRetka_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSTipRetka_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSTipRetka_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOSTipRetka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSTipRetka_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[fin].[tblOSTipRetka]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSTipRetka_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSTipRetka_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSTipRetka_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOSTipRetka table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSTipRetka_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [fin].[tblOSTipRetka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblOSTipRetka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSTipRetka_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSTipRetka_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSTipRetka_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOSTipRetka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSTipRetka_Insert
(

	@ID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblOSTipRetka]
					(
					[ID]
					,[Naziv]
					)
				VALUES
					(
					@ID
					,@Naziv
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSTipRetka_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSTipRetka_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSTipRetka_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOSTipRetka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSTipRetka_Update
(

	@ID int   ,

	@OriginalID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblOSTipRetka]
				SET
					[ID] = @ID
					,[Naziv] = @Naziv
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSTipRetka_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSTipRetka_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSTipRetka_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOSTipRetka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSTipRetka_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblOSTipRetka] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSTipRetka_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSTipRetka_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSTipRetka_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSTipRetka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSTipRetka_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[fin].[tblOSTipRetka]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSTipRetka_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSTipRetka_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSTipRetka_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOSTipRetka table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSTipRetka_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[fin].[tblOSTipRetka]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[fin].[tblOSTipRetka]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblPrimanjeTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Postotak],
					[OsnovaOsiguranja],
					[VrstaRada],
					[IndikatorID],
					[IDVrstaRaspodjele]
				FROM
					[pla].[tblPrimanjeTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblPrimanjeTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Postotak]'
				SET @SQL = @SQL + ', [OsnovaOsiguranja]'
				SET @SQL = @SQL + ', [VrstaRada]'
				SET @SQL = @SQL + ', [IndikatorID]'
				SET @SQL = @SQL + ', [IDVrstaRaspodjele]'
				SET @SQL = @SQL + ' FROM [pla].[tblPrimanjeTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Postotak],'
				SET @SQL = @SQL + ' [OsnovaOsiguranja],'
				SET @SQL = @SQL + ' [VrstaRada],'
				SET @SQL = @SQL + ' [IndikatorID],'
				SET @SQL = @SQL + ' [IDVrstaRaspodjele]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblPrimanjeTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblPrimanjeTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (100)  ,

	@Postotak money   ,

	@OsnovaOsiguranja int   ,

	@VrstaRada int   ,

	@IndikatorID int   ,

	@IDVrstaRaspodjele int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblPrimanjeTip]
					(
					[Naziv]
					,[Postotak]
					,[OsnovaOsiguranja]
					,[VrstaRada]
					,[IndikatorID]
					,[IDVrstaRaspodjele]
					)
				VALUES
					(
					@Naziv
					,@Postotak
					,@OsnovaOsiguranja
					,@VrstaRada
					,@IndikatorID
					,@IDVrstaRaspodjele
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblPrimanjeTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_Update
(

	@ID int   ,

	@Naziv nvarchar (100)  ,

	@Postotak money   ,

	@OsnovaOsiguranja int   ,

	@VrstaRada int   ,

	@IndikatorID int   ,

	@IDVrstaRaspodjele int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblPrimanjeTip]
				SET
					[Naziv] = @Naziv
					,[Postotak] = @Postotak
					,[OsnovaOsiguranja] = @OsnovaOsiguranja
					,[VrstaRada] = @VrstaRada
					,[IndikatorID] = @IndikatorID
					,[IDVrstaRaspodjele] = @IDVrstaRaspodjele
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblPrimanjeTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblPrimanjeTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_GetByIndikatorID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_GetByIndikatorID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_GetByIndikatorID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPrimanjeTip table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_GetByIndikatorID
(

	@IndikatorID int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Postotak],
					[OsnovaOsiguranja],
					[VrstaRada],
					[IndikatorID],
					[IDVrstaRaspodjele]
				FROM
					[pla].[tblPrimanjeTip]
				WHERE
					[IndikatorID] = @IndikatorID
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_GetByVrstaRada procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_GetByVrstaRada') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_GetByVrstaRada
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPrimanjeTip table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_GetByVrstaRada
(

	@VrstaRada int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Postotak],
					[OsnovaOsiguranja],
					[VrstaRada],
					[IndikatorID],
					[IDVrstaRaspodjele]
				FROM
					[pla].[tblPrimanjeTip]
				WHERE
					[VrstaRada] = @VrstaRada
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_GetByOsnovaOsiguranja procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_GetByOsnovaOsiguranja') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_GetByOsnovaOsiguranja
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPrimanjeTip table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_GetByOsnovaOsiguranja
(

	@OsnovaOsiguranja int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Postotak],
					[OsnovaOsiguranja],
					[VrstaRada],
					[IndikatorID],
					[IDVrstaRaspodjele]
				FROM
					[pla].[tblPrimanjeTip]
				WHERE
					[OsnovaOsiguranja] = @OsnovaOsiguranja
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_GetByIDVrstaRaspodjele procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_GetByIDVrstaRaspodjele') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_GetByIDVrstaRaspodjele
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPrimanjeTip table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_GetByIDVrstaRaspodjele
(

	@IDVrstaRaspodjele int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Postotak],
					[OsnovaOsiguranja],
					[VrstaRada],
					[IndikatorID],
					[IDVrstaRaspodjele]
				FROM
					[pla].[tblPrimanjeTip]
				WHERE
					[IDVrstaRaspodjele] = @IDVrstaRaspodjele
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPrimanjeTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[Postotak],
					[OsnovaOsiguranja],
					[VrstaRada],
					[IndikatorID],
					[IDVrstaRaspodjele]
				FROM
					[pla].[tblPrimanjeTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblPrimanjeTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblPrimanjeTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblPrimanjeTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblPrimanjeTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblPrimanjeTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (100)  = null ,

	@Postotak money   = null ,

	@OsnovaOsiguranja int   = null ,

	@VrstaRada int   = null ,

	@IndikatorID int   = null ,

	@IDVrstaRaspodjele int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Postotak]
	, [OsnovaOsiguranja]
	, [VrstaRada]
	, [IndikatorID]
	, [IDVrstaRaspodjele]
    FROM
	[pla].[tblPrimanjeTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Postotak] = @Postotak OR @Postotak is null)
	AND ([OsnovaOsiguranja] = @OsnovaOsiguranja OR @OsnovaOsiguranja is null)
	AND ([VrstaRada] = @VrstaRada OR @VrstaRada is null)
	AND ([IndikatorID] = @IndikatorID OR @IndikatorID is null)
	AND ([IDVrstaRaspodjele] = @IDVrstaRaspodjele OR @IDVrstaRaspodjele is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Postotak]
	, [OsnovaOsiguranja]
	, [VrstaRada]
	, [IndikatorID]
	, [IDVrstaRaspodjele]
    FROM
	[pla].[tblPrimanjeTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Postotak] = @Postotak AND @Postotak is not null)
	OR ([OsnovaOsiguranja] = @OsnovaOsiguranja AND @OsnovaOsiguranja is not null)
	OR ([VrstaRada] = @VrstaRada AND @VrstaRada is not null)
	OR ([IndikatorID] = @IndikatorID AND @IndikatorID is not null)
	OR ([IDVrstaRaspodjele] = @IDVrstaRaspodjele AND @IDVrstaRaspodjele is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOsnovnoSredstvo_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOsnovnoSredstvo_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOsnovnoSredstvo_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsnovnoSredstvo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOsnovnoSredstvo_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDParentOS],
					[IDDobavljac],
					[Naziv],
					[Sifra],
					[Kolicina],
					[DatumKnjizenja],
					[Opis],
					[Napomena],
					[TvBroj],
					[Detalji]
				FROM
					[fin].[tblOsnovnoSredstvo]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOsnovnoSredstvo_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOsnovnoSredstvo_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOsnovnoSredstvo_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsnovnoSredstvo table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOsnovnoSredstvo_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDParentOS]'
				SET @SQL = @SQL + ', [IDDobavljac]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Sifra]'
				SET @SQL = @SQL + ', [Kolicina]'
				SET @SQL = @SQL + ', [DatumKnjizenja]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [TvBroj]'
				SET @SQL = @SQL + ', [Detalji]'
				SET @SQL = @SQL + ' FROM [fin].[tblOsnovnoSredstvo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDParentOS],'
				SET @SQL = @SQL + ' [IDDobavljac],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Sifra],'
				SET @SQL = @SQL + ' [Kolicina],'
				SET @SQL = @SQL + ' [DatumKnjizenja],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [TvBroj],'
				SET @SQL = @SQL + ' [Detalji]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblOsnovnoSredstvo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOsnovnoSredstvo_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOsnovnoSredstvo_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOsnovnoSredstvo_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsnovnoSredstvo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOsnovnoSredstvo_Insert
(

	@ID int    OUTPUT,

	@IDParentOS int   ,

	@IDDobavljac int   ,

	@Naziv nvarchar (100)  ,

	@Sifra nvarchar (50)  ,

	@Kolicina money   ,

	@DatumKnjizenja datetime   ,

	@Opis nvarchar (400)  ,

	@Napomena nvarchar (400)  ,

	@TvBroj nvarchar (50)  ,

	@Detalji nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblOsnovnoSredstvo]
					(
					[IDParentOS]
					,[IDDobavljac]
					,[Naziv]
					,[Sifra]
					,[Kolicina]
					,[DatumKnjizenja]
					,[Opis]
					,[Napomena]
					,[TvBroj]
					,[Detalji]
					)
				VALUES
					(
					@IDParentOS
					,@IDDobavljac
					,@Naziv
					,@Sifra
					,@Kolicina
					,@DatumKnjizenja
					,@Opis
					,@Napomena
					,@TvBroj
					,@Detalji
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOsnovnoSredstvo_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOsnovnoSredstvo_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOsnovnoSredstvo_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsnovnoSredstvo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOsnovnoSredstvo_Update
(

	@ID int   ,

	@IDParentOS int   ,

	@IDDobavljac int   ,

	@Naziv nvarchar (100)  ,

	@Sifra nvarchar (50)  ,

	@Kolicina money   ,

	@DatumKnjizenja datetime   ,

	@Opis nvarchar (400)  ,

	@Napomena nvarchar (400)  ,

	@TvBroj nvarchar (50)  ,

	@Detalji nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblOsnovnoSredstvo]
				SET
					[IDParentOS] = @IDParentOS
					,[IDDobavljac] = @IDDobavljac
					,[Naziv] = @Naziv
					,[Sifra] = @Sifra
					,[Kolicina] = @Kolicina
					,[DatumKnjizenja] = @DatumKnjizenja
					,[Opis] = @Opis
					,[Napomena] = @Napomena
					,[TvBroj] = @TvBroj
					,[Detalji] = @Detalji
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOsnovnoSredstvo_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOsnovnoSredstvo_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOsnovnoSredstvo_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsnovnoSredstvo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOsnovnoSredstvo_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblOsnovnoSredstvo] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOsnovnoSredstvo_GetByIDDobavljac procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOsnovnoSredstvo_GetByIDDobavljac') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOsnovnoSredstvo_GetByIDDobavljac
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsnovnoSredstvo table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOsnovnoSredstvo_GetByIDDobavljac
(

	@IDDobavljac int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDParentOS],
					[IDDobavljac],
					[Naziv],
					[Sifra],
					[Kolicina],
					[DatumKnjizenja],
					[Opis],
					[Napomena],
					[TvBroj],
					[Detalji]
				FROM
					[fin].[tblOsnovnoSredstvo]
				WHERE
					[IDDobavljac] = @IDDobavljac
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOsnovnoSredstvo_GetByIDParentOS procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOsnovnoSredstvo_GetByIDParentOS') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOsnovnoSredstvo_GetByIDParentOS
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsnovnoSredstvo table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOsnovnoSredstvo_GetByIDParentOS
(

	@IDParentOS int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDParentOS],
					[IDDobavljac],
					[Naziv],
					[Sifra],
					[Kolicina],
					[DatumKnjizenja],
					[Opis],
					[Napomena],
					[TvBroj],
					[Detalji]
				FROM
					[fin].[tblOsnovnoSredstvo]
				WHERE
					[IDParentOS] = @IDParentOS
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOsnovnoSredstvo_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOsnovnoSredstvo_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOsnovnoSredstvo_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsnovnoSredstvo table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOsnovnoSredstvo_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDParentOS],
					[IDDobavljac],
					[Naziv],
					[Sifra],
					[Kolicina],
					[DatumKnjizenja],
					[Opis],
					[Napomena],
					[TvBroj],
					[Detalji]
				FROM
					[fin].[tblOsnovnoSredstvo]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOsnovnoSredstvo_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOsnovnoSredstvo_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOsnovnoSredstvo_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsnovnoSredstvo table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOsnovnoSredstvo_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDParentOS int   = null ,

	@IDDobavljac int   = null ,

	@Naziv nvarchar (100)  = null ,

	@Sifra nvarchar (50)  = null ,

	@Kolicina money   = null ,

	@DatumKnjizenja datetime   = null ,

	@Opis nvarchar (400)  = null ,

	@Napomena nvarchar (400)  = null ,

	@TvBroj nvarchar (50)  = null ,

	@Detalji nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDParentOS]
	, [IDDobavljac]
	, [Naziv]
	, [Sifra]
	, [Kolicina]
	, [DatumKnjizenja]
	, [Opis]
	, [Napomena]
	, [TvBroj]
	, [Detalji]
    FROM
	[fin].[tblOsnovnoSredstvo]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDParentOS] = @IDParentOS OR @IDParentOS is null)
	AND ([IDDobavljac] = @IDDobavljac OR @IDDobavljac is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Sifra] = @Sifra OR @Sifra is null)
	AND ([Kolicina] = @Kolicina OR @Kolicina is null)
	AND ([DatumKnjizenja] = @DatumKnjizenja OR @DatumKnjizenja is null)
	AND ([Opis] = @Opis OR @Opis is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([TvBroj] = @TvBroj OR @TvBroj is null)
	AND ([Detalji] = @Detalji OR @Detalji is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDParentOS]
	, [IDDobavljac]
	, [Naziv]
	, [Sifra]
	, [Kolicina]
	, [DatumKnjizenja]
	, [Opis]
	, [Napomena]
	, [TvBroj]
	, [Detalji]
    FROM
	[fin].[tblOsnovnoSredstvo]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDParentOS] = @IDParentOS AND @IDParentOS is not null)
	OR ([IDDobavljac] = @IDDobavljac AND @IDDobavljac is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Sifra] = @Sifra AND @Sifra is not null)
	OR ([Kolicina] = @Kolicina AND @Kolicina is not null)
	OR ([DatumKnjizenja] = @DatumKnjizenja AND @DatumKnjizenja is not null)
	OR ([Opis] = @Opis AND @Opis is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([TvBroj] = @TvBroj AND @TvBroj is not null)
	OR ([Detalji] = @Detalji AND @Detalji is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOrganizacijaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblOrganizacijaTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOrganizacijaTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [dbo].[tblOrganizacijaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblOrganizacijaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOrganizacijaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblOrganizacijaTip]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOrganizacijaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaTip_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblOrganizacijaTip]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOrganizacijaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblOrganizacijaTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaTip_GetByNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaTip_GetByNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaTip_GetByNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijaTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaTip_GetByNaziv
(

	@Naziv nvarchar (50)  
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblOrganizacijaTip]
				WHERE
					[Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijaTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblOrganizacijaTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOrganizacijaTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblOrganizacijaTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblOrganizacijaTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOrganizacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDTip],
					[SifraSkladista],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[Poreznibroj],
					[OznakaDjelatnosti],
					[NadleznaIspostavaPorUp],
					[OrgOIB],
					[CalculatedHierarchy]
				FROM
					[dbo].[tblOrganizacija]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOrganizacija table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [IDRoditelj]'
				SET @SQL = @SQL + ', [Hierarchy]'
				SET @SQL = @SQL + ', [Lvl]'
				SET @SQL = @SQL + ', [IDTip]'
				SET @SQL = @SQL + ', [SifraSkladista]'
				SET @SQL = @SQL + ', [Grupa]'
				SET @SQL = @SQL + ', [Telefon]'
				SET @SQL = @SQL + ', [Fax]'
				SET @SQL = @SQL + ', [Adresa]'
				SET @SQL = @SQL + ', [EMail]'
				SET @SQL = @SQL + ', [IDMjesto]'
				SET @SQL = @SQL + ', [Direktor]'
				SET @SQL = @SQL + ', [Poreznibroj]'
				SET @SQL = @SQL + ', [OznakaDjelatnosti]'
				SET @SQL = @SQL + ', [NadleznaIspostavaPorUp]'
				SET @SQL = @SQL + ', [OrgOIB]'
				SET @SQL = @SQL + ', [CalculatedHierarchy]'
				SET @SQL = @SQL + ' FROM [dbo].[tblOrganizacija]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [IDRoditelj],'
				SET @SQL = @SQL + ' [Hierarchy],'
				SET @SQL = @SQL + ' [Lvl],'
				SET @SQL = @SQL + ' [IDTip],'
				SET @SQL = @SQL + ' [SifraSkladista],'
				SET @SQL = @SQL + ' [Grupa],'
				SET @SQL = @SQL + ' [Telefon],'
				SET @SQL = @SQL + ' [Fax],'
				SET @SQL = @SQL + ' [Adresa],'
				SET @SQL = @SQL + ' [EMail],'
				SET @SQL = @SQL + ' [IDMjesto],'
				SET @SQL = @SQL + ' [Direktor],'
				SET @SQL = @SQL + ' [Poreznibroj],'
				SET @SQL = @SQL + ' [OznakaDjelatnosti],'
				SET @SQL = @SQL + ' [NadleznaIspostavaPorUp],'
				SET @SQL = @SQL + ' [OrgOIB],'
				SET @SQL = @SQL + ' [CalculatedHierarchy]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblOrganizacija]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOrganizacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  ,

	@IDRoditelj int   ,

	@Hierarchy nvarchar (200)  ,

	@Lvl int    OUTPUT,

	@IDTip int   ,

	@SifraSkladista varchar (50)  ,

	@Grupa nvarchar (50)  ,

	@Telefon nvarchar (50)  ,

	@Fax nvarchar (50)  ,

	@Adresa nvarchar (200)  ,

	@EMail nvarchar (50)  ,

	@IDMjesto int   ,

	@Direktor nvarchar (100)  ,

	@Poreznibroj nvarchar (50)  ,

	@OznakaDjelatnosti nvarchar (100)  ,

	@NadleznaIspostavaPorUp nvarchar (100)  ,

	@OrgOIB nvarchar (50)  ,

	@CalculatedHierarchy nvarchar (200)   OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblOrganizacija]
					(
					[Naziv]
					,[IDRoditelj]
					,[Hierarchy]
					,[IDTip]
					,[SifraSkladista]
					,[Grupa]
					,[Telefon]
					,[Fax]
					,[Adresa]
					,[EMail]
					,[IDMjesto]
					,[Direktor]
					,[Poreznibroj]
					,[OznakaDjelatnosti]
					,[NadleznaIspostavaPorUp]
					,[OrgOIB]
					)
				VALUES
					(
					@Naziv
					,@IDRoditelj
					,@Hierarchy
					,@IDTip
					,@SifraSkladista
					,@Grupa
					,@Telefon
					,@Fax
					,@Adresa
					,@EMail
					,@IDMjesto
					,@Direktor
					,@Poreznibroj
					,@OznakaDjelatnosti
					,@NadleznaIspostavaPorUp
					,@OrgOIB
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
				-- Select computed columns into output parameters
				SELECT
 @Lvl = [Lvl]
, @CalculatedHierarchy = [CalculatedHierarchy]
				FROM
					[dbo].[tblOrganizacija]
				WHERE
[ID] = @ID 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOrganizacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  ,

	@IDRoditelj int   ,

	@Hierarchy nvarchar (200)  ,

	@Lvl int    OUTPUT,

	@IDTip int   ,

	@SifraSkladista varchar (50)  ,

	@Grupa nvarchar (50)  ,

	@Telefon nvarchar (50)  ,

	@Fax nvarchar (50)  ,

	@Adresa nvarchar (200)  ,

	@EMail nvarchar (50)  ,

	@IDMjesto int   ,

	@Direktor nvarchar (100)  ,

	@Poreznibroj nvarchar (50)  ,

	@OznakaDjelatnosti nvarchar (100)  ,

	@NadleznaIspostavaPorUp nvarchar (100)  ,

	@OrgOIB nvarchar (50)  ,

	@CalculatedHierarchy nvarchar (200)   OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblOrganizacija]
				SET
					[Naziv] = @Naziv
					,[IDRoditelj] = @IDRoditelj
					,[Hierarchy] = @Hierarchy
					,[IDTip] = @IDTip
					,[SifraSkladista] = @SifraSkladista
					,[Grupa] = @Grupa
					,[Telefon] = @Telefon
					,[Fax] = @Fax
					,[Adresa] = @Adresa
					,[EMail] = @EMail
					,[IDMjesto] = @IDMjesto
					,[Direktor] = @Direktor
					,[Poreznibroj] = @Poreznibroj
					,[OznakaDjelatnosti] = @OznakaDjelatnosti
					,[NadleznaIspostavaPorUp] = @NadleznaIspostavaPorUp
					,[OrgOIB] = @OrgOIB
				WHERE
[ID] = @ID 
				
				
				-- Select computed columns into output parameters
				SELECT
 @Lvl = [Lvl]
, @CalculatedHierarchy = [CalculatedHierarchy]
				FROM
					[dbo].[tblOrganizacija]
				WHERE
[ID] = @ID 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOrganizacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblOrganizacija] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_GetByIDMjesto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_GetByIDMjesto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_GetByIDMjesto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacija table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_GetByIDMjesto
(

	@IDMjesto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDTip],
					[SifraSkladista],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[Poreznibroj],
					[OznakaDjelatnosti],
					[NadleznaIspostavaPorUp],
					[OrgOIB],
					[CalculatedHierarchy]
				FROM
					[dbo].[tblOrganizacija]
				WHERE
					[IDMjesto] = @IDMjesto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_GetByIDRoditelj procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_GetByIDRoditelj') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_GetByIDRoditelj
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacija table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_GetByIDRoditelj
(

	@IDRoditelj int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDTip],
					[SifraSkladista],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[Poreznibroj],
					[OznakaDjelatnosti],
					[NadleznaIspostavaPorUp],
					[OrgOIB],
					[CalculatedHierarchy]
				FROM
					[dbo].[tblOrganizacija]
				WHERE
					[IDRoditelj] = @IDRoditelj
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_GetByIDTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_GetByIDTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_GetByIDTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacija table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_GetByIDTip
(

	@IDTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDTip],
					[SifraSkladista],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[Poreznibroj],
					[OznakaDjelatnosti],
					[NadleznaIspostavaPorUp],
					[OrgOIB],
					[CalculatedHierarchy]
				FROM
					[dbo].[tblOrganizacija]
				WHERE
					[IDTip] = @IDTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_GetByHierarchy procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_GetByHierarchy') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_GetByHierarchy
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacija table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_GetByHierarchy
(

	@Hierarchy nvarchar (200)  
)
AS


				SELECT
					[ID],
					[Naziv],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDTip],
					[SifraSkladista],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[Poreznibroj],
					[OznakaDjelatnosti],
					[NadleznaIspostavaPorUp],
					[OrgOIB],
					[CalculatedHierarchy]
				FROM
					[dbo].[tblOrganizacija]
				WHERE
					[Hierarchy] = @Hierarchy
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_GetBySifraSkladista procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_GetBySifraSkladista') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_GetBySifraSkladista
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacija table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_GetBySifraSkladista
(

	@SifraSkladista varchar (50)  
)
AS


				SELECT
					[ID],
					[Naziv],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDTip],
					[SifraSkladista],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[Poreznibroj],
					[OznakaDjelatnosti],
					[NadleznaIspostavaPorUp],
					[OrgOIB],
					[CalculatedHierarchy]
				FROM
					[dbo].[tblOrganizacija]
				WHERE
					[SifraSkladista] = @SifraSkladista
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacija table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDTip],
					[SifraSkladista],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[Poreznibroj],
					[OznakaDjelatnosti],
					[NadleznaIspostavaPorUp],
					[OrgOIB],
					[CalculatedHierarchy]
				FROM
					[dbo].[tblOrganizacija]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacija_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacija_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacija_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOrganizacija table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacija_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null ,

	@IDRoditelj int   = null ,

	@Hierarchy nvarchar (200)  = null ,

	@Lvl int   = null ,

	@IDTip int   = null ,

	@SifraSkladista varchar (50)  = null ,

	@Grupa nvarchar (50)  = null ,

	@Telefon nvarchar (50)  = null ,

	@Fax nvarchar (50)  = null ,

	@Adresa nvarchar (200)  = null ,

	@EMail nvarchar (50)  = null ,

	@IDMjesto int   = null ,

	@Direktor nvarchar (100)  = null ,

	@Poreznibroj nvarchar (50)  = null ,

	@OznakaDjelatnosti nvarchar (100)  = null ,

	@NadleznaIspostavaPorUp nvarchar (100)  = null ,

	@OrgOIB nvarchar (50)  = null ,

	@CalculatedHierarchy nvarchar (200)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [IDRoditelj]
	, [Hierarchy]
	, [Lvl]
	, [IDTip]
	, [SifraSkladista]
	, [Grupa]
	, [Telefon]
	, [Fax]
	, [Adresa]
	, [EMail]
	, [IDMjesto]
	, [Direktor]
	, [Poreznibroj]
	, [OznakaDjelatnosti]
	, [NadleznaIspostavaPorUp]
	, [OrgOIB]
	, [CalculatedHierarchy]
    FROM
	[dbo].[tblOrganizacija]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([IDRoditelj] = @IDRoditelj OR @IDRoditelj is null)
	AND ([Hierarchy] = @Hierarchy OR @Hierarchy is null)
	AND ([Lvl] = @Lvl OR @Lvl is null)
	AND ([IDTip] = @IDTip OR @IDTip is null)
	AND ([SifraSkladista] = @SifraSkladista OR @SifraSkladista is null)
	AND ([Grupa] = @Grupa OR @Grupa is null)
	AND ([Telefon] = @Telefon OR @Telefon is null)
	AND ([Fax] = @Fax OR @Fax is null)
	AND ([Adresa] = @Adresa OR @Adresa is null)
	AND ([EMail] = @EMail OR @EMail is null)
	AND ([IDMjesto] = @IDMjesto OR @IDMjesto is null)
	AND ([Direktor] = @Direktor OR @Direktor is null)
	AND ([Poreznibroj] = @Poreznibroj OR @Poreznibroj is null)
	AND ([OznakaDjelatnosti] = @OznakaDjelatnosti OR @OznakaDjelatnosti is null)
	AND ([NadleznaIspostavaPorUp] = @NadleznaIspostavaPorUp OR @NadleznaIspostavaPorUp is null)
	AND ([OrgOIB] = @OrgOIB OR @OrgOIB is null)
	AND ([CalculatedHierarchy] = @CalculatedHierarchy OR @CalculatedHierarchy is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [IDRoditelj]
	, [Hierarchy]
	, [Lvl]
	, [IDTip]
	, [SifraSkladista]
	, [Grupa]
	, [Telefon]
	, [Fax]
	, [Adresa]
	, [EMail]
	, [IDMjesto]
	, [Direktor]
	, [Poreznibroj]
	, [OznakaDjelatnosti]
	, [NadleznaIspostavaPorUp]
	, [OrgOIB]
	, [CalculatedHierarchy]
    FROM
	[dbo].[tblOrganizacija]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([IDRoditelj] = @IDRoditelj AND @IDRoditelj is not null)
	OR ([Hierarchy] = @Hierarchy AND @Hierarchy is not null)
	OR ([Lvl] = @Lvl AND @Lvl is not null)
	OR ([IDTip] = @IDTip AND @IDTip is not null)
	OR ([SifraSkladista] = @SifraSkladista AND @SifraSkladista is not null)
	OR ([Grupa] = @Grupa AND @Grupa is not null)
	OR ([Telefon] = @Telefon AND @Telefon is not null)
	OR ([Fax] = @Fax AND @Fax is not null)
	OR ([Adresa] = @Adresa AND @Adresa is not null)
	OR ([EMail] = @EMail AND @EMail is not null)
	OR ([IDMjesto] = @IDMjesto AND @IDMjesto is not null)
	OR ([Direktor] = @Direktor AND @Direktor is not null)
	OR ([Poreznibroj] = @Poreznibroj AND @Poreznibroj is not null)
	OR ([OznakaDjelatnosti] = @OznakaDjelatnosti AND @OznakaDjelatnosti is not null)
	OR ([NadleznaIspostavaPorUp] = @NadleznaIspostavaPorUp AND @NadleznaIspostavaPorUp is not null)
	OR ([OrgOIB] = @OrgOIB AND @OrgOIB is not null)
	OR ([CalculatedHierarchy] = @CalculatedHierarchy AND @CalculatedHierarchy is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVrstaFinDokumenta_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVrstaFinDokumenta_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVrstaFinDokumenta_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblVrstaFinDokumenta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVrstaFinDokumenta_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Sifra]
				FROM
					[fin].[tblVrstaFinDokumenta]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVrstaFinDokumenta_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVrstaFinDokumenta_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVrstaFinDokumenta_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblVrstaFinDokumenta table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVrstaFinDokumenta_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Sifra]'
				SET @SQL = @SQL + ' FROM [fin].[tblVrstaFinDokumenta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Sifra]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblVrstaFinDokumenta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVrstaFinDokumenta_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVrstaFinDokumenta_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVrstaFinDokumenta_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblVrstaFinDokumenta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVrstaFinDokumenta_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (250)  ,

	@Sifra nvarchar (10)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblVrstaFinDokumenta]
					(
					[Naziv]
					,[Sifra]
					)
				VALUES
					(
					@Naziv
					,@Sifra
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVrstaFinDokumenta_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVrstaFinDokumenta_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVrstaFinDokumenta_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblVrstaFinDokumenta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVrstaFinDokumenta_Update
(

	@ID int   ,

	@Naziv nvarchar (250)  ,

	@Sifra nvarchar (10)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblVrstaFinDokumenta]
				SET
					[Naziv] = @Naziv
					,[Sifra] = @Sifra
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVrstaFinDokumenta_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVrstaFinDokumenta_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVrstaFinDokumenta_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblVrstaFinDokumenta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVrstaFinDokumenta_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblVrstaFinDokumenta] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVrstaFinDokumenta_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVrstaFinDokumenta_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVrstaFinDokumenta_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblVrstaFinDokumenta table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVrstaFinDokumenta_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[Sifra]
				FROM
					[fin].[tblVrstaFinDokumenta]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVrstaFinDokumenta_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVrstaFinDokumenta_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVrstaFinDokumenta_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblVrstaFinDokumenta table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVrstaFinDokumenta_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (250)  = null ,

	@Sifra nvarchar (10)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Sifra]
    FROM
	[fin].[tblVrstaFinDokumenta]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Sifra] = @Sifra OR @Sifra is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Sifra]
    FROM
	[fin].[tblVrstaFinDokumenta]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Sifra] = @Sifra AND @Sifra is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaZiroRacun_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaZiroRacun_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaZiroRacun_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOrganizacijaZiroRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaZiroRacun_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrganizacija],
					[ZiroRacun],
					[Konto],
					[IDVrstaFinDokumenta]
				FROM
					[dbo].[tblOrganizacijaZiroRacun]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaZiroRacun_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaZiroRacun_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaZiroRacun_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOrganizacijaZiroRacun table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaZiroRacun_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOrganizacija]'
				SET @SQL = @SQL + ', [ZiroRacun]'
				SET @SQL = @SQL + ', [Konto]'
				SET @SQL = @SQL + ', [IDVrstaFinDokumenta]'
				SET @SQL = @SQL + ' FROM [dbo].[tblOrganizacijaZiroRacun]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOrganizacija],'
				SET @SQL = @SQL + ' [ZiroRacun],'
				SET @SQL = @SQL + ' [Konto],'
				SET @SQL = @SQL + ' [IDVrstaFinDokumenta]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblOrganizacijaZiroRacun]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaZiroRacun_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaZiroRacun_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaZiroRacun_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOrganizacijaZiroRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaZiroRacun_Insert
(

	@ID int    OUTPUT,

	@IDOrganizacija int   ,

	@ZiroRacun nvarchar (18)  ,

	@Konto varchar (9)  ,

	@IDVrstaFinDokumenta int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblOrganizacijaZiroRacun]
					(
					[IDOrganizacija]
					,[ZiroRacun]
					,[Konto]
					,[IDVrstaFinDokumenta]
					)
				VALUES
					(
					@IDOrganizacija
					,@ZiroRacun
					,@Konto
					,@IDVrstaFinDokumenta
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaZiroRacun_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaZiroRacun_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaZiroRacun_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOrganizacijaZiroRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaZiroRacun_Update
(

	@ID int   ,

	@IDOrganizacija int   ,

	@ZiroRacun nvarchar (18)  ,

	@Konto varchar (9)  ,

	@IDVrstaFinDokumenta int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblOrganizacijaZiroRacun]
				SET
					[IDOrganizacija] = @IDOrganizacija
					,[ZiroRacun] = @ZiroRacun
					,[Konto] = @Konto
					,[IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaZiroRacun_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaZiroRacun_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaZiroRacun_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOrganizacijaZiroRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaZiroRacun_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblOrganizacijaZiroRacun] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaZiroRacun_GetByIDOrganizacija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaZiroRacun_GetByIDOrganizacija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaZiroRacun_GetByIDOrganizacija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijaZiroRacun table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaZiroRacun_GetByIDOrganizacija
(

	@IDOrganizacija int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrganizacija],
					[ZiroRacun],
					[Konto],
					[IDVrstaFinDokumenta]
				FROM
					[dbo].[tblOrganizacijaZiroRacun]
				WHERE
					[IDOrganizacija] = @IDOrganizacija
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaZiroRacun_GetByIDVrstaFinDokumenta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaZiroRacun_GetByIDVrstaFinDokumenta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaZiroRacun_GetByIDVrstaFinDokumenta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijaZiroRacun table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaZiroRacun_GetByIDVrstaFinDokumenta
(

	@IDVrstaFinDokumenta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrganizacija],
					[ZiroRacun],
					[Konto],
					[IDVrstaFinDokumenta]
				FROM
					[dbo].[tblOrganizacijaZiroRacun]
				WHERE
					[IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaZiroRacun_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaZiroRacun_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaZiroRacun_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijaZiroRacun table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaZiroRacun_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOrganizacija],
					[ZiroRacun],
					[Konto],
					[IDVrstaFinDokumenta]
				FROM
					[dbo].[tblOrganizacijaZiroRacun]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblOrganizacijaZiroRacun_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblOrganizacijaZiroRacun_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblOrganizacijaZiroRacun_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOrganizacijaZiroRacun table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblOrganizacijaZiroRacun_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOrganizacija int   = null ,

	@ZiroRacun nvarchar (18)  = null ,

	@Konto varchar (9)  = null ,

	@IDVrstaFinDokumenta int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOrganizacija]
	, [ZiroRacun]
	, [Konto]
	, [IDVrstaFinDokumenta]
    FROM
	[dbo].[tblOrganizacijaZiroRacun]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOrganizacija] = @IDOrganizacija OR @IDOrganizacija is null)
	AND ([ZiroRacun] = @ZiroRacun OR @ZiroRacun is null)
	AND ([Konto] = @Konto OR @Konto is null)
	AND ([IDVrstaFinDokumenta] = @IDVrstaFinDokumenta OR @IDVrstaFinDokumenta is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOrganizacija]
	, [ZiroRacun]
	, [Konto]
	, [IDVrstaFinDokumenta]
    FROM
	[dbo].[tblOrganizacijaZiroRacun]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOrganizacija] = @IDOrganizacija AND @IDOrganizacija is not null)
	OR ([ZiroRacun] = @ZiroRacun AND @ZiroRacun is not null)
	OR ([Konto] = @Konto AND @Konto is not null)
	OR ([IDVrstaFinDokumenta] = @IDVrstaFinDokumenta AND @IDVrstaFinDokumenta is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipKonta_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipKonta_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipKonta_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblTipKonta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipKonta_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[fin].[tblTipKonta]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipKonta_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipKonta_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipKonta_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblTipKonta table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipKonta_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [fin].[tblTipKonta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblTipKonta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipKonta_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipKonta_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipKonta_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblTipKonta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipKonta_Insert
(

	@ID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblTipKonta]
					(
					[ID]
					,[Naziv]
					)
				VALUES
					(
					@ID
					,@Naziv
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipKonta_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipKonta_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipKonta_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblTipKonta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipKonta_Update
(

	@ID int   ,

	@OriginalID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblTipKonta]
				SET
					[ID] = @ID
					,[Naziv] = @Naziv
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipKonta_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipKonta_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipKonta_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblTipKonta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipKonta_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblTipKonta] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipKonta_GetByNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipKonta_GetByNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipKonta_GetByNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblTipKonta table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipKonta_GetByNaziv
(

	@Naziv nvarchar (50)  
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[fin].[tblTipKonta]
				WHERE
					[Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipKonta_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipKonta_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipKonta_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblTipKonta table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipKonta_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[fin].[tblTipKonta]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipKonta_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipKonta_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipKonta_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblTipKonta table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipKonta_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[fin].[tblTipKonta]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[fin].[tblTipKonta]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObustavaNaknadaTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObustavaNaknadaTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObustavaNaknadaTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObustavaNaknadaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObustavaNaknadaTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[FaktorObracuna],
					[PoreznaOlaksica]
				FROM
					[pla].[tblObustavaNaknadaTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObustavaNaknadaTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObustavaNaknadaTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObustavaNaknadaTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObustavaNaknadaTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObustavaNaknadaTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [FaktorObracuna]'
				SET @SQL = @SQL + ', [PoreznaOlaksica]'
				SET @SQL = @SQL + ' FROM [pla].[tblObustavaNaknadaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [FaktorObracuna],'
				SET @SQL = @SQL + ' [PoreznaOlaksica]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblObustavaNaknadaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObustavaNaknadaTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObustavaNaknadaTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObustavaNaknadaTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObustavaNaknadaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObustavaNaknadaTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  ,

	@FaktorObracuna int   ,

	@PoreznaOlaksica int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblObustavaNaknadaTip]
					(
					[Naziv]
					,[FaktorObracuna]
					,[PoreznaOlaksica]
					)
				VALUES
					(
					@Naziv
					,@FaktorObracuna
					,@PoreznaOlaksica
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObustavaNaknadaTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObustavaNaknadaTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObustavaNaknadaTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObustavaNaknadaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObustavaNaknadaTip_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  ,

	@FaktorObracuna int   ,

	@PoreznaOlaksica int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblObustavaNaknadaTip]
				SET
					[Naziv] = @Naziv
					,[FaktorObracuna] = @FaktorObracuna
					,[PoreznaOlaksica] = @PoreznaOlaksica
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObustavaNaknadaTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObustavaNaknadaTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObustavaNaknadaTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObustavaNaknadaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObustavaNaknadaTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblObustavaNaknadaTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObustavaNaknadaTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObustavaNaknadaTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObustavaNaknadaTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObustavaNaknadaTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObustavaNaknadaTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[FaktorObracuna],
					[PoreznaOlaksica]
				FROM
					[pla].[tblObustavaNaknadaTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObustavaNaknadaTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObustavaNaknadaTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObustavaNaknadaTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObustavaNaknadaTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObustavaNaknadaTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null ,

	@FaktorObracuna int   = null ,

	@PoreznaOlaksica int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [FaktorObracuna]
	, [PoreznaOlaksica]
    FROM
	[pla].[tblObustavaNaknadaTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([FaktorObracuna] = @FaktorObracuna OR @FaktorObracuna is null)
	AND ([PoreznaOlaksica] = @PoreznaOlaksica OR @PoreznaOlaksica is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [FaktorObracuna]
	, [PoreznaOlaksica]
    FROM
	[pla].[tblObustavaNaknadaTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([FaktorObracuna] = @FaktorObracuna AND @FaktorObracuna is not null)
	OR ([PoreznaOlaksica] = @PoreznaOlaksica AND @PoreznaOlaksica is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOrganizacijskaJedinicaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblOrganizacijskaJedinicaTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOrganizacijskaJedinicaTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [pla].[tblOrganizacijskaJedinicaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOrganizacijskaJedinicaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOrganizacijskaJedinicaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOrganizacijskaJedinicaTip]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOrganizacijskaJedinicaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaTip_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOrganizacijskaJedinicaTip]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOrganizacijskaJedinicaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOrganizacijskaJedinicaTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijskaJedinicaTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblOrganizacijskaJedinicaTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOrganizacijskaJedinicaTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblOrganizacijskaJedinicaTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblOrganizacijskaJedinicaTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOSKartica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[Datum],
					[Kolicina],
					[IDTipRetka],
					[IDOrgJed],
					[IDOsoba],
					[Napomena],
					[IDStatus],
					[NabVr],
					[Vrijednost],
					[Zbroj],
					[Ispravak],
					[AmVrijednost],
					[KnjizVrijednost],
					[IDUserCreated],
					[DatumZapisa]
				FROM
					[fin].[tblOSKartica]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOSKartica table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOS]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [Kolicina]'
				SET @SQL = @SQL + ', [IDTipRetka]'
				SET @SQL = @SQL + ', [IDOrgJed]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ', [NabVr]'
				SET @SQL = @SQL + ', [Vrijednost]'
				SET @SQL = @SQL + ', [Zbroj]'
				SET @SQL = @SQL + ', [Ispravak]'
				SET @SQL = @SQL + ', [AmVrijednost]'
				SET @SQL = @SQL + ', [KnjizVrijednost]'
				SET @SQL = @SQL + ', [IDUserCreated]'
				SET @SQL = @SQL + ', [DatumZapisa]'
				SET @SQL = @SQL + ' FROM [fin].[tblOSKartica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOS],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [Kolicina],'
				SET @SQL = @SQL + ' [IDTipRetka],'
				SET @SQL = @SQL + ' [IDOrgJed],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [IDStatus],'
				SET @SQL = @SQL + ' [NabVr],'
				SET @SQL = @SQL + ' [Vrijednost],'
				SET @SQL = @SQL + ' [Zbroj],'
				SET @SQL = @SQL + ' [Ispravak],'
				SET @SQL = @SQL + ' [AmVrijednost],'
				SET @SQL = @SQL + ' [KnjizVrijednost],'
				SET @SQL = @SQL + ' [IDUserCreated],'
				SET @SQL = @SQL + ' [DatumZapisa]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblOSKartica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOSKartica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_Insert
(

	@ID int    OUTPUT,

	@IDOS int   ,

	@Datum datetime   ,

	@Kolicina money   ,

	@IDTipRetka int   ,

	@IDOrgJed int   ,

	@IDOsoba int   ,

	@Napomena nvarchar (50)  ,

	@IDStatus int   ,

	@NabVr money   ,

	@Vrijednost money   ,

	@Zbroj money   ,

	@Ispravak money   ,

	@AmVrijednost money   ,

	@KnjizVrijednost money   ,

	@IDUserCreated int   ,

	@DatumZapisa datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblOSKartica]
					(
					[IDOS]
					,[Datum]
					,[Kolicina]
					,[IDTipRetka]
					,[IDOrgJed]
					,[IDOsoba]
					,[Napomena]
					,[IDStatus]
					,[NabVr]
					,[Vrijednost]
					,[Zbroj]
					,[Ispravak]
					,[AmVrijednost]
					,[KnjizVrijednost]
					,[IDUserCreated]
					,[DatumZapisa]
					)
				VALUES
					(
					@IDOS
					,@Datum
					,@Kolicina
					,@IDTipRetka
					,@IDOrgJed
					,@IDOsoba
					,@Napomena
					,@IDStatus
					,@NabVr
					,@Vrijednost
					,@Zbroj
					,@Ispravak
					,@AmVrijednost
					,@KnjizVrijednost
					,@IDUserCreated
					,@DatumZapisa
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOSKartica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_Update
(

	@ID int   ,

	@IDOS int   ,

	@Datum datetime   ,

	@Kolicina money   ,

	@IDTipRetka int   ,

	@IDOrgJed int   ,

	@IDOsoba int   ,

	@Napomena nvarchar (50)  ,

	@IDStatus int   ,

	@NabVr money   ,

	@Vrijednost money   ,

	@Zbroj money   ,

	@Ispravak money   ,

	@AmVrijednost money   ,

	@KnjizVrijednost money   ,

	@IDUserCreated int   ,

	@DatumZapisa datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblOSKartica]
				SET
					[IDOS] = @IDOS
					,[Datum] = @Datum
					,[Kolicina] = @Kolicina
					,[IDTipRetka] = @IDTipRetka
					,[IDOrgJed] = @IDOrgJed
					,[IDOsoba] = @IDOsoba
					,[Napomena] = @Napomena
					,[IDStatus] = @IDStatus
					,[NabVr] = @NabVr
					,[Vrijednost] = @Vrijednost
					,[Zbroj] = @Zbroj
					,[Ispravak] = @Ispravak
					,[AmVrijednost] = @AmVrijednost
					,[KnjizVrijednost] = @KnjizVrijednost
					,[IDUserCreated] = @IDUserCreated
					,[DatumZapisa] = @DatumZapisa
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOSKartica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblOSKartica] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_GetByIDOrgJed procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_GetByIDOrgJed') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_GetByIDOrgJed
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSKartica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_GetByIDOrgJed
(

	@IDOrgJed int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[Datum],
					[Kolicina],
					[IDTipRetka],
					[IDOrgJed],
					[IDOsoba],
					[Napomena],
					[IDStatus],
					[NabVr],
					[Vrijednost],
					[Zbroj],
					[Ispravak],
					[AmVrijednost],
					[KnjizVrijednost],
					[IDUserCreated],
					[DatumZapisa]
				FROM
					[fin].[tblOSKartica]
				WHERE
					[IDOrgJed] = @IDOrgJed
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_GetByIDOS procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_GetByIDOS') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_GetByIDOS
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSKartica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_GetByIDOS
(

	@IDOS int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[Datum],
					[Kolicina],
					[IDTipRetka],
					[IDOrgJed],
					[IDOsoba],
					[Napomena],
					[IDStatus],
					[NabVr],
					[Vrijednost],
					[Zbroj],
					[Ispravak],
					[AmVrijednost],
					[KnjizVrijednost],
					[IDUserCreated],
					[DatumZapisa]
				FROM
					[fin].[tblOSKartica]
				WHERE
					[IDOS] = @IDOS
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSKartica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[Datum],
					[Kolicina],
					[IDTipRetka],
					[IDOrgJed],
					[IDOsoba],
					[Napomena],
					[IDStatus],
					[NabVr],
					[Vrijednost],
					[Zbroj],
					[Ispravak],
					[AmVrijednost],
					[KnjizVrijednost],
					[IDUserCreated],
					[DatumZapisa]
				FROM
					[fin].[tblOSKartica]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_GetByIDTipRetka procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_GetByIDTipRetka') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_GetByIDTipRetka
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSKartica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_GetByIDTipRetka
(

	@IDTipRetka int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[Datum],
					[Kolicina],
					[IDTipRetka],
					[IDOrgJed],
					[IDOsoba],
					[Napomena],
					[IDStatus],
					[NabVr],
					[Vrijednost],
					[Zbroj],
					[Ispravak],
					[AmVrijednost],
					[KnjizVrijednost],
					[IDUserCreated],
					[DatumZapisa]
				FROM
					[fin].[tblOSKartica]
				WHERE
					[IDTipRetka] = @IDTipRetka
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSKartica table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOS],
					[Datum],
					[Kolicina],
					[IDTipRetka],
					[IDOrgJed],
					[IDOsoba],
					[Napomena],
					[IDStatus],
					[NabVr],
					[Vrijednost],
					[Zbroj],
					[Ispravak],
					[AmVrijednost],
					[KnjizVrijednost],
					[IDUserCreated],
					[DatumZapisa]
				FROM
					[fin].[tblOSKartica]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSKartica_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSKartica_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSKartica_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOSKartica table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSKartica_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOS int   = null ,

	@Datum datetime   = null ,

	@Kolicina money   = null ,

	@IDTipRetka int   = null ,

	@IDOrgJed int   = null ,

	@IDOsoba int   = null ,

	@Napomena nvarchar (50)  = null ,

	@IDStatus int   = null ,

	@NabVr money   = null ,

	@Vrijednost money   = null ,

	@Zbroj money   = null ,

	@Ispravak money   = null ,

	@AmVrijednost money   = null ,

	@KnjizVrijednost money   = null ,

	@IDUserCreated int   = null ,

	@DatumZapisa datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOS]
	, [Datum]
	, [Kolicina]
	, [IDTipRetka]
	, [IDOrgJed]
	, [IDOsoba]
	, [Napomena]
	, [IDStatus]
	, [NabVr]
	, [Vrijednost]
	, [Zbroj]
	, [Ispravak]
	, [AmVrijednost]
	, [KnjizVrijednost]
	, [IDUserCreated]
	, [DatumZapisa]
    FROM
	[fin].[tblOSKartica]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOS] = @IDOS OR @IDOS is null)
	AND ([Datum] = @Datum OR @Datum is null)
	AND ([Kolicina] = @Kolicina OR @Kolicina is null)
	AND ([IDTipRetka] = @IDTipRetka OR @IDTipRetka is null)
	AND ([IDOrgJed] = @IDOrgJed OR @IDOrgJed is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([IDStatus] = @IDStatus OR @IDStatus is null)
	AND ([NabVr] = @NabVr OR @NabVr is null)
	AND ([Vrijednost] = @Vrijednost OR @Vrijednost is null)
	AND ([Zbroj] = @Zbroj OR @Zbroj is null)
	AND ([Ispravak] = @Ispravak OR @Ispravak is null)
	AND ([AmVrijednost] = @AmVrijednost OR @AmVrijednost is null)
	AND ([KnjizVrijednost] = @KnjizVrijednost OR @KnjizVrijednost is null)
	AND ([IDUserCreated] = @IDUserCreated OR @IDUserCreated is null)
	AND ([DatumZapisa] = @DatumZapisa OR @DatumZapisa is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOS]
	, [Datum]
	, [Kolicina]
	, [IDTipRetka]
	, [IDOrgJed]
	, [IDOsoba]
	, [Napomena]
	, [IDStatus]
	, [NabVr]
	, [Vrijednost]
	, [Zbroj]
	, [Ispravak]
	, [AmVrijednost]
	, [KnjizVrijednost]
	, [IDUserCreated]
	, [DatumZapisa]
    FROM
	[fin].[tblOSKartica]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOS] = @IDOS AND @IDOS is not null)
	OR ([Datum] = @Datum AND @Datum is not null)
	OR ([Kolicina] = @Kolicina AND @Kolicina is not null)
	OR ([IDTipRetka] = @IDTipRetka AND @IDTipRetka is not null)
	OR ([IDOrgJed] = @IDOrgJed AND @IDOrgJed is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([IDStatus] = @IDStatus AND @IDStatus is not null)
	OR ([NabVr] = @NabVr AND @NabVr is not null)
	OR ([Vrijednost] = @Vrijednost AND @Vrijednost is not null)
	OR ([Zbroj] = @Zbroj AND @Zbroj is not null)
	OR ([Ispravak] = @Ispravak AND @Ispravak is not null)
	OR ([AmVrijednost] = @AmVrijednost AND @AmVrijednost is not null)
	OR ([KnjizVrijednost] = @KnjizVrijednost AND @KnjizVrijednost is not null)
	OR ([IDUserCreated] = @IDUserCreated AND @IDUserCreated is not null)
	OR ([DatumZapisa] = @DatumZapisa AND @DatumZapisa is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaZiroRacun_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaZiroRacun_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOrganizacijskaJedinicaZiroRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrganizacijskaJedinica],
					[ZiroRacun],
					[Konto]
				FROM
					[pla].[tblOrganizacijskaJedinicaZiroRacun]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaZiroRacun_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaZiroRacun_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOrganizacijskaJedinicaZiroRacun table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOrganizacijskaJedinica]'
				SET @SQL = @SQL + ', [ZiroRacun]'
				SET @SQL = @SQL + ', [Konto]'
				SET @SQL = @SQL + ' FROM [pla].[tblOrganizacijskaJedinicaZiroRacun]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOrganizacijskaJedinica],'
				SET @SQL = @SQL + ' [ZiroRacun],'
				SET @SQL = @SQL + ' [Konto]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOrganizacijskaJedinicaZiroRacun]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaZiroRacun_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaZiroRacun_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOrganizacijskaJedinicaZiroRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_Insert
(

	@ID int    OUTPUT,

	@IDOrganizacijskaJedinica int   ,

	@ZiroRacun nvarchar (18)  ,

	@Konto varchar (9)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOrganizacijskaJedinicaZiroRacun]
					(
					[IDOrganizacijskaJedinica]
					,[ZiroRacun]
					,[Konto]
					)
				VALUES
					(
					@IDOrganizacijskaJedinica
					,@ZiroRacun
					,@Konto
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaZiroRacun_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaZiroRacun_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOrganizacijskaJedinicaZiroRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_Update
(

	@ID int   ,

	@IDOrganizacijskaJedinica int   ,

	@ZiroRacun nvarchar (18)  ,

	@Konto varchar (9)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOrganizacijskaJedinicaZiroRacun]
				SET
					[IDOrganizacijskaJedinica] = @IDOrganizacijskaJedinica
					,[ZiroRacun] = @ZiroRacun
					,[Konto] = @Konto
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaZiroRacun_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaZiroRacun_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOrganizacijskaJedinicaZiroRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOrganizacijskaJedinicaZiroRacun] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaZiroRacun_GetByIDOrganizacijskaJedinica procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaZiroRacun_GetByIDOrganizacijskaJedinica') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_GetByIDOrganizacijskaJedinica
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijskaJedinicaZiroRacun table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_GetByIDOrganizacijskaJedinica
(

	@IDOrganizacijskaJedinica int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrganizacijskaJedinica],
					[ZiroRacun],
					[Konto]
				FROM
					[pla].[tblOrganizacijskaJedinicaZiroRacun]
				WHERE
					[IDOrganizacijskaJedinica] = @IDOrganizacijskaJedinica
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaZiroRacun_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaZiroRacun_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijskaJedinicaZiroRacun table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOrganizacijskaJedinica],
					[ZiroRacun],
					[Konto]
				FROM
					[pla].[tblOrganizacijskaJedinicaZiroRacun]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinicaZiroRacun_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinicaZiroRacun_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOrganizacijskaJedinicaZiroRacun table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinicaZiroRacun_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOrganizacijskaJedinica int   = null ,

	@ZiroRacun nvarchar (18)  = null ,

	@Konto varchar (9)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOrganizacijskaJedinica]
	, [ZiroRacun]
	, [Konto]
    FROM
	[pla].[tblOrganizacijskaJedinicaZiroRacun]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOrganizacijskaJedinica] = @IDOrganizacijskaJedinica OR @IDOrganizacijskaJedinica is null)
	AND ([ZiroRacun] = @ZiroRacun OR @ZiroRacun is null)
	AND ([Konto] = @Konto OR @Konto is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOrganizacijskaJedinica]
	, [ZiroRacun]
	, [Konto]
    FROM
	[pla].[tblOrganizacijskaJedinicaZiroRacun]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOrganizacijskaJedinica] = @IDOrganizacijskaJedinica AND @IDOrganizacijskaJedinica is not null)
	OR ([ZiroRacun] = @ZiroRacun AND @ZiroRacun is not null)
	OR ([Konto] = @Konto AND @Konto is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSGrupa_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSGrupa_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSGrupa_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOSGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSGrupa_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Oznaka],
					[Naziv],
					[IDKontoNabavka],
					[IDKontoIspravka],
					[IDKontoTroska],
					[RedBr]
				FROM
					[fin].[tblOSGrupa]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSGrupa_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSGrupa_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSGrupa_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOSGrupa table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSGrupa_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [IDKontoNabavka]'
				SET @SQL = @SQL + ', [IDKontoIspravka]'
				SET @SQL = @SQL + ', [IDKontoTroska]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ' FROM [fin].[tblOSGrupa]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [IDKontoNabavka],'
				SET @SQL = @SQL + ' [IDKontoIspravka],'
				SET @SQL = @SQL + ' [IDKontoTroska],'
				SET @SQL = @SQL + ' [RedBr]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblOSGrupa]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSGrupa_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSGrupa_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSGrupa_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOSGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSGrupa_Insert
(

	@ID int    OUTPUT,

	@Oznaka nvarchar (10)  ,

	@Naziv nvarchar (50)  ,

	@IDKontoNabavka int   ,

	@IDKontoIspravka int   ,

	@IDKontoTroska int   ,

	@RedBr int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblOSGrupa]
					(
					[Oznaka]
					,[Naziv]
					,[IDKontoNabavka]
					,[IDKontoIspravka]
					,[IDKontoTroska]
					,[RedBr]
					)
				VALUES
					(
					@Oznaka
					,@Naziv
					,@IDKontoNabavka
					,@IDKontoIspravka
					,@IDKontoTroska
					,@RedBr
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSGrupa_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSGrupa_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSGrupa_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOSGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSGrupa_Update
(

	@ID int   ,

	@Oznaka nvarchar (10)  ,

	@Naziv nvarchar (50)  ,

	@IDKontoNabavka int   ,

	@IDKontoIspravka int   ,

	@IDKontoTroska int   ,

	@RedBr int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblOSGrupa]
				SET
					[Oznaka] = @Oznaka
					,[Naziv] = @Naziv
					,[IDKontoNabavka] = @IDKontoNabavka
					,[IDKontoIspravka] = @IDKontoIspravka
					,[IDKontoTroska] = @IDKontoTroska
					,[RedBr] = @RedBr
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSGrupa_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSGrupa_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSGrupa_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOSGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSGrupa_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblOSGrupa] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSGrupa_GetByIDKontoNabavka procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSGrupa_GetByIDKontoNabavka') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSGrupa_GetByIDKontoNabavka
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSGrupa table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSGrupa_GetByIDKontoNabavka
(

	@IDKontoNabavka int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Oznaka],
					[Naziv],
					[IDKontoNabavka],
					[IDKontoIspravka],
					[IDKontoTroska],
					[RedBr]
				FROM
					[fin].[tblOSGrupa]
				WHERE
					[IDKontoNabavka] = @IDKontoNabavka
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSGrupa_GetByIDKontoIspravka procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSGrupa_GetByIDKontoIspravka') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSGrupa_GetByIDKontoIspravka
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSGrupa table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSGrupa_GetByIDKontoIspravka
(

	@IDKontoIspravka int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Oznaka],
					[Naziv],
					[IDKontoNabavka],
					[IDKontoIspravka],
					[IDKontoTroska],
					[RedBr]
				FROM
					[fin].[tblOSGrupa]
				WHERE
					[IDKontoIspravka] = @IDKontoIspravka
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSGrupa_GetByIDKontoTroska procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSGrupa_GetByIDKontoTroska') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSGrupa_GetByIDKontoTroska
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSGrupa table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSGrupa_GetByIDKontoTroska
(

	@IDKontoTroska int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Oznaka],
					[Naziv],
					[IDKontoNabavka],
					[IDKontoIspravka],
					[IDKontoTroska],
					[RedBr]
				FROM
					[fin].[tblOSGrupa]
				WHERE
					[IDKontoTroska] = @IDKontoTroska
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSGrupa_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSGrupa_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSGrupa_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSGrupa table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSGrupa_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Oznaka],
					[Naziv],
					[IDKontoNabavka],
					[IDKontoIspravka],
					[IDKontoTroska],
					[RedBr]
				FROM
					[fin].[tblOSGrupa]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSGrupa_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSGrupa_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSGrupa_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOSGrupa table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSGrupa_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Oznaka nvarchar (10)  = null ,

	@Naziv nvarchar (50)  = null ,

	@IDKontoNabavka int   = null ,

	@IDKontoIspravka int   = null ,

	@IDKontoTroska int   = null ,

	@RedBr int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Oznaka]
	, [Naziv]
	, [IDKontoNabavka]
	, [IDKontoIspravka]
	, [IDKontoTroska]
	, [RedBr]
    FROM
	[fin].[tblOSGrupa]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Oznaka] = @Oznaka OR @Oznaka is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([IDKontoNabavka] = @IDKontoNabavka OR @IDKontoNabavka is null)
	AND ([IDKontoIspravka] = @IDKontoIspravka OR @IDKontoIspravka is null)
	AND ([IDKontoTroska] = @IDKontoTroska OR @IDKontoTroska is null)
	AND ([RedBr] = @RedBr OR @RedBr is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Oznaka]
	, [Naziv]
	, [IDKontoNabavka]
	, [IDKontoIspravka]
	, [IDKontoTroska]
	, [RedBr]
    FROM
	[fin].[tblOSGrupa]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Oznaka] = @Oznaka AND @Oznaka is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([IDKontoNabavka] = @IDKontoNabavka AND @IDKontoNabavka is not null)
	OR ([IDKontoIspravka] = @IDKontoIspravka AND @IDKontoIspravka is not null)
	OR ([IDKontoTroska] = @IDKontoTroska AND @IDKontoTroska is not null)
	OR ([RedBr] = @RedBr AND @RedBr is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsnovaOsiguranjaTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsnovaOsiguranjaTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsnovaOsiguranjaTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOsnovaOsiguranjaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsnovaOsiguranjaTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblOsnovaOsiguranjaTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsnovaOsiguranjaTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsnovaOsiguranjaTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsnovaOsiguranjaTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOsnovaOsiguranjaTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsnovaOsiguranjaTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [pla].[tblOsnovaOsiguranjaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOsnovaOsiguranjaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsnovaOsiguranjaTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsnovaOsiguranjaTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsnovaOsiguranjaTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOsnovaOsiguranjaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsnovaOsiguranjaTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOsnovaOsiguranjaTip]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsnovaOsiguranjaTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsnovaOsiguranjaTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsnovaOsiguranjaTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOsnovaOsiguranjaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsnovaOsiguranjaTip_Update
(

	@ID int   ,

	@Naziv nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOsnovaOsiguranjaTip]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsnovaOsiguranjaTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsnovaOsiguranjaTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsnovaOsiguranjaTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOsnovaOsiguranjaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsnovaOsiguranjaTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOsnovaOsiguranjaTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsnovaOsiguranjaTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsnovaOsiguranjaTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsnovaOsiguranjaTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOsnovaOsiguranjaTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsnovaOsiguranjaTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblOsnovaOsiguranjaTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOsnovaOsiguranjaTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOsnovaOsiguranjaTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOsnovaOsiguranjaTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOsnovaOsiguranjaTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOsnovaOsiguranjaTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (100)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblOsnovaOsiguranjaTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblOsnovaOsiguranjaTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinica_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinica_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinica_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOrganizacijskaJedinica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinica_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[SkraceniNaziv],
					[Poreznibroj],
					[MaticniBrojSubjekta],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDOrganizacijskaJedinicaTip],
					[Sifra],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[CalculatedHierarchy],
					[DefaultVrstaObveznikaRSM],
					[DefaultVrijednostDoprinosaZaBoravakUInozemstvu],
					[OIB]
				FROM
					[pla].[tblOrganizacijskaJedinica]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinica_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinica_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinica_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOrganizacijskaJedinica table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinica_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [SkraceniNaziv]'
				SET @SQL = @SQL + ', [Poreznibroj]'
				SET @SQL = @SQL + ', [MaticniBrojSubjekta]'
				SET @SQL = @SQL + ', [IDRoditelj]'
				SET @SQL = @SQL + ', [Hierarchy]'
				SET @SQL = @SQL + ', [Lvl]'
				SET @SQL = @SQL + ', [IDOrganizacijskaJedinicaTip]'
				SET @SQL = @SQL + ', [Sifra]'
				SET @SQL = @SQL + ', [Grupa]'
				SET @SQL = @SQL + ', [Telefon]'
				SET @SQL = @SQL + ', [Fax]'
				SET @SQL = @SQL + ', [Adresa]'
				SET @SQL = @SQL + ', [EMail]'
				SET @SQL = @SQL + ', [IDMjesto]'
				SET @SQL = @SQL + ', [Direktor]'
				SET @SQL = @SQL + ', [CalculatedHierarchy]'
				SET @SQL = @SQL + ', [DefaultVrstaObveznikaRSM]'
				SET @SQL = @SQL + ', [DefaultVrijednostDoprinosaZaBoravakUInozemstvu]'
				SET @SQL = @SQL + ', [OIB]'
				SET @SQL = @SQL + ' FROM [pla].[tblOrganizacijskaJedinica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [SkraceniNaziv],'
				SET @SQL = @SQL + ' [Poreznibroj],'
				SET @SQL = @SQL + ' [MaticniBrojSubjekta],'
				SET @SQL = @SQL + ' [IDRoditelj],'
				SET @SQL = @SQL + ' [Hierarchy],'
				SET @SQL = @SQL + ' [Lvl],'
				SET @SQL = @SQL + ' [IDOrganizacijskaJedinicaTip],'
				SET @SQL = @SQL + ' [Sifra],'
				SET @SQL = @SQL + ' [Grupa],'
				SET @SQL = @SQL + ' [Telefon],'
				SET @SQL = @SQL + ' [Fax],'
				SET @SQL = @SQL + ' [Adresa],'
				SET @SQL = @SQL + ' [EMail],'
				SET @SQL = @SQL + ' [IDMjesto],'
				SET @SQL = @SQL + ' [Direktor],'
				SET @SQL = @SQL + ' [CalculatedHierarchy],'
				SET @SQL = @SQL + ' [DefaultVrstaObveznikaRSM],'
				SET @SQL = @SQL + ' [DefaultVrijednostDoprinosaZaBoravakUInozemstvu],'
				SET @SQL = @SQL + ' [OIB]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblOrganizacijskaJedinica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinica_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinica_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinica_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOrganizacijskaJedinica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinica_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (200)  ,

	@SkraceniNaziv nvarchar (50)  ,

	@Poreznibroj nvarchar (50)  ,

	@MaticniBrojSubjekta nvarchar (15)  ,

	@IDRoditelj int   ,

	@Hierarchy nvarchar (200)  ,

	@Lvl int    OUTPUT,

	@IDOrganizacijskaJedinicaTip int   ,

	@Sifra varchar (50)  ,

	@Grupa nvarchar (50)  ,

	@Telefon nvarchar (50)  ,

	@Fax nvarchar (50)  ,

	@Adresa nvarchar (200)  ,

	@EMail nvarchar (50)  ,

	@IDMjesto int   ,

	@Direktor nvarchar (100)  ,

	@CalculatedHierarchy nvarchar (200)   OUTPUT,

	@DefaultVrstaObveznikaRSM int   ,

	@DefaultVrijednostDoprinosaZaBoravakUInozemstvu money   ,

	@OIB nvarchar (11)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblOrganizacijskaJedinica]
					(
					[Naziv]
					,[SkraceniNaziv]
					,[Poreznibroj]
					,[MaticniBrojSubjekta]
					,[IDRoditelj]
					,[Hierarchy]
					,[IDOrganizacijskaJedinicaTip]
					,[Sifra]
					,[Grupa]
					,[Telefon]
					,[Fax]
					,[Adresa]
					,[EMail]
					,[IDMjesto]
					,[Direktor]
					,[DefaultVrstaObveznikaRSM]
					,[DefaultVrijednostDoprinosaZaBoravakUInozemstvu]
					,[OIB]
					)
				VALUES
					(
					@Naziv
					,@SkraceniNaziv
					,@Poreznibroj
					,@MaticniBrojSubjekta
					,@IDRoditelj
					,@Hierarchy
					,@IDOrganizacijskaJedinicaTip
					,@Sifra
					,@Grupa
					,@Telefon
					,@Fax
					,@Adresa
					,@EMail
					,@IDMjesto
					,@Direktor
					,@DefaultVrstaObveznikaRSM
					,@DefaultVrijednostDoprinosaZaBoravakUInozemstvu
					,@OIB
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
				-- Select computed columns into output parameters
				SELECT
 @Lvl = [Lvl]
, @CalculatedHierarchy = [CalculatedHierarchy]
				FROM
					[pla].[tblOrganizacijskaJedinica]
				WHERE
[ID] = @ID 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinica_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinica_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinica_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOrganizacijskaJedinica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinica_Update
(

	@ID int   ,

	@Naziv nvarchar (200)  ,

	@SkraceniNaziv nvarchar (50)  ,

	@Poreznibroj nvarchar (50)  ,

	@MaticniBrojSubjekta nvarchar (15)  ,

	@IDRoditelj int   ,

	@Hierarchy nvarchar (200)  ,

	@Lvl int    OUTPUT,

	@IDOrganizacijskaJedinicaTip int   ,

	@Sifra varchar (50)  ,

	@Grupa nvarchar (50)  ,

	@Telefon nvarchar (50)  ,

	@Fax nvarchar (50)  ,

	@Adresa nvarchar (200)  ,

	@EMail nvarchar (50)  ,

	@IDMjesto int   ,

	@Direktor nvarchar (100)  ,

	@CalculatedHierarchy nvarchar (200)   OUTPUT,

	@DefaultVrstaObveznikaRSM int   ,

	@DefaultVrijednostDoprinosaZaBoravakUInozemstvu money   ,

	@OIB nvarchar (11)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblOrganizacijskaJedinica]
				SET
					[Naziv] = @Naziv
					,[SkraceniNaziv] = @SkraceniNaziv
					,[Poreznibroj] = @Poreznibroj
					,[MaticniBrojSubjekta] = @MaticniBrojSubjekta
					,[IDRoditelj] = @IDRoditelj
					,[Hierarchy] = @Hierarchy
					,[IDOrganizacijskaJedinicaTip] = @IDOrganizacijskaJedinicaTip
					,[Sifra] = @Sifra
					,[Grupa] = @Grupa
					,[Telefon] = @Telefon
					,[Fax] = @Fax
					,[Adresa] = @Adresa
					,[EMail] = @EMail
					,[IDMjesto] = @IDMjesto
					,[Direktor] = @Direktor
					,[DefaultVrstaObveznikaRSM] = @DefaultVrstaObveznikaRSM
					,[DefaultVrijednostDoprinosaZaBoravakUInozemstvu] = @DefaultVrijednostDoprinosaZaBoravakUInozemstvu
					,[OIB] = @OIB
				WHERE
[ID] = @ID 
				
				
				-- Select computed columns into output parameters
				SELECT
 @Lvl = [Lvl]
, @CalculatedHierarchy = [CalculatedHierarchy]
				FROM
					[pla].[tblOrganizacijskaJedinica]
				WHERE
[ID] = @ID 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinica_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinica_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinica_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOrganizacijskaJedinica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinica_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblOrganizacijskaJedinica] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinica_GetByIDMjesto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinica_GetByIDMjesto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinica_GetByIDMjesto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijskaJedinica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinica_GetByIDMjesto
(

	@IDMjesto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[SkraceniNaziv],
					[Poreznibroj],
					[MaticniBrojSubjekta],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDOrganizacijskaJedinicaTip],
					[Sifra],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[CalculatedHierarchy],
					[DefaultVrstaObveznikaRSM],
					[DefaultVrijednostDoprinosaZaBoravakUInozemstvu],
					[OIB]
				FROM
					[pla].[tblOrganizacijskaJedinica]
				WHERE
					[IDMjesto] = @IDMjesto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinica_GetByIDRoditelj procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinica_GetByIDRoditelj') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinica_GetByIDRoditelj
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijskaJedinica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinica_GetByIDRoditelj
(

	@IDRoditelj int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[SkraceniNaziv],
					[Poreznibroj],
					[MaticniBrojSubjekta],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDOrganizacijskaJedinicaTip],
					[Sifra],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[CalculatedHierarchy],
					[DefaultVrstaObveznikaRSM],
					[DefaultVrijednostDoprinosaZaBoravakUInozemstvu],
					[OIB]
				FROM
					[pla].[tblOrganizacijskaJedinica]
				WHERE
					[IDRoditelj] = @IDRoditelj
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinica_GetByIDOrganizacijskaJedinicaTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinica_GetByIDOrganizacijskaJedinicaTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinica_GetByIDOrganizacijskaJedinicaTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijskaJedinica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinica_GetByIDOrganizacijskaJedinicaTip
(

	@IDOrganizacijskaJedinicaTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[SkraceniNaziv],
					[Poreznibroj],
					[MaticniBrojSubjekta],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDOrganizacijskaJedinicaTip],
					[Sifra],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[CalculatedHierarchy],
					[DefaultVrstaObveznikaRSM],
					[DefaultVrijednostDoprinosaZaBoravakUInozemstvu],
					[OIB]
				FROM
					[pla].[tblOrganizacijskaJedinica]
				WHERE
					[IDOrganizacijskaJedinicaTip] = @IDOrganizacijskaJedinicaTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinica_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinica_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinica_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOrganizacijskaJedinica table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinica_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[SkraceniNaziv],
					[Poreznibroj],
					[MaticniBrojSubjekta],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[IDOrganizacijskaJedinicaTip],
					[Sifra],
					[Grupa],
					[Telefon],
					[Fax],
					[Adresa],
					[EMail],
					[IDMjesto],
					[Direktor],
					[CalculatedHierarchy],
					[DefaultVrstaObveznikaRSM],
					[DefaultVrijednostDoprinosaZaBoravakUInozemstvu],
					[OIB]
				FROM
					[pla].[tblOrganizacijskaJedinica]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblOrganizacijskaJedinica_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblOrganizacijskaJedinica_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblOrganizacijskaJedinica_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOrganizacijskaJedinica table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblOrganizacijskaJedinica_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (200)  = null ,

	@SkraceniNaziv nvarchar (50)  = null ,

	@Poreznibroj nvarchar (50)  = null ,

	@MaticniBrojSubjekta nvarchar (15)  = null ,

	@IDRoditelj int   = null ,

	@Hierarchy nvarchar (200)  = null ,

	@Lvl int   = null ,

	@IDOrganizacijskaJedinicaTip int   = null ,

	@Sifra varchar (50)  = null ,

	@Grupa nvarchar (50)  = null ,

	@Telefon nvarchar (50)  = null ,

	@Fax nvarchar (50)  = null ,

	@Adresa nvarchar (200)  = null ,

	@EMail nvarchar (50)  = null ,

	@IDMjesto int   = null ,

	@Direktor nvarchar (100)  = null ,

	@CalculatedHierarchy nvarchar (200)  = null ,

	@DefaultVrstaObveznikaRSM int   = null ,

	@DefaultVrijednostDoprinosaZaBoravakUInozemstvu money   = null ,

	@OIB nvarchar (11)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [SkraceniNaziv]
	, [Poreznibroj]
	, [MaticniBrojSubjekta]
	, [IDRoditelj]
	, [Hierarchy]
	, [Lvl]
	, [IDOrganizacijskaJedinicaTip]
	, [Sifra]
	, [Grupa]
	, [Telefon]
	, [Fax]
	, [Adresa]
	, [EMail]
	, [IDMjesto]
	, [Direktor]
	, [CalculatedHierarchy]
	, [DefaultVrstaObveznikaRSM]
	, [DefaultVrijednostDoprinosaZaBoravakUInozemstvu]
	, [OIB]
    FROM
	[pla].[tblOrganizacijskaJedinica]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([SkraceniNaziv] = @SkraceniNaziv OR @SkraceniNaziv is null)
	AND ([Poreznibroj] = @Poreznibroj OR @Poreznibroj is null)
	AND ([MaticniBrojSubjekta] = @MaticniBrojSubjekta OR @MaticniBrojSubjekta is null)
	AND ([IDRoditelj] = @IDRoditelj OR @IDRoditelj is null)
	AND ([Hierarchy] = @Hierarchy OR @Hierarchy is null)
	AND ([Lvl] = @Lvl OR @Lvl is null)
	AND ([IDOrganizacijskaJedinicaTip] = @IDOrganizacijskaJedinicaTip OR @IDOrganizacijskaJedinicaTip is null)
	AND ([Sifra] = @Sifra OR @Sifra is null)
	AND ([Grupa] = @Grupa OR @Grupa is null)
	AND ([Telefon] = @Telefon OR @Telefon is null)
	AND ([Fax] = @Fax OR @Fax is null)
	AND ([Adresa] = @Adresa OR @Adresa is null)
	AND ([EMail] = @EMail OR @EMail is null)
	AND ([IDMjesto] = @IDMjesto OR @IDMjesto is null)
	AND ([Direktor] = @Direktor OR @Direktor is null)
	AND ([CalculatedHierarchy] = @CalculatedHierarchy OR @CalculatedHierarchy is null)
	AND ([DefaultVrstaObveznikaRSM] = @DefaultVrstaObveznikaRSM OR @DefaultVrstaObveznikaRSM is null)
	AND ([DefaultVrijednostDoprinosaZaBoravakUInozemstvu] = @DefaultVrijednostDoprinosaZaBoravakUInozemstvu OR @DefaultVrijednostDoprinosaZaBoravakUInozemstvu is null)
	AND ([OIB] = @OIB OR @OIB is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [SkraceniNaziv]
	, [Poreznibroj]
	, [MaticniBrojSubjekta]
	, [IDRoditelj]
	, [Hierarchy]
	, [Lvl]
	, [IDOrganizacijskaJedinicaTip]
	, [Sifra]
	, [Grupa]
	, [Telefon]
	, [Fax]
	, [Adresa]
	, [EMail]
	, [IDMjesto]
	, [Direktor]
	, [CalculatedHierarchy]
	, [DefaultVrstaObveznikaRSM]
	, [DefaultVrijednostDoprinosaZaBoravakUInozemstvu]
	, [OIB]
    FROM
	[pla].[tblOrganizacijskaJedinica]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([SkraceniNaziv] = @SkraceniNaziv AND @SkraceniNaziv is not null)
	OR ([Poreznibroj] = @Poreznibroj AND @Poreznibroj is not null)
	OR ([MaticniBrojSubjekta] = @MaticniBrojSubjekta AND @MaticniBrojSubjekta is not null)
	OR ([IDRoditelj] = @IDRoditelj AND @IDRoditelj is not null)
	OR ([Hierarchy] = @Hierarchy AND @Hierarchy is not null)
	OR ([Lvl] = @Lvl AND @Lvl is not null)
	OR ([IDOrganizacijskaJedinicaTip] = @IDOrganizacijskaJedinicaTip AND @IDOrganizacijskaJedinicaTip is not null)
	OR ([Sifra] = @Sifra AND @Sifra is not null)
	OR ([Grupa] = @Grupa AND @Grupa is not null)
	OR ([Telefon] = @Telefon AND @Telefon is not null)
	OR ([Fax] = @Fax AND @Fax is not null)
	OR ([Adresa] = @Adresa AND @Adresa is not null)
	OR ([EMail] = @EMail AND @EMail is not null)
	OR ([IDMjesto] = @IDMjesto AND @IDMjesto is not null)
	OR ([Direktor] = @Direktor AND @Direktor is not null)
	OR ([CalculatedHierarchy] = @CalculatedHierarchy AND @CalculatedHierarchy is not null)
	OR ([DefaultVrstaObveznikaRSM] = @DefaultVrstaObveznikaRSM AND @DefaultVrstaObveznikaRSM is not null)
	OR ([DefaultVrijednostDoprinosaZaBoravakUInozemstvu] = @DefaultVrijednostDoprinosaZaBoravakUInozemstvu AND @DefaultVrijednostDoprinosaZaBoravakUInozemstvu is not null)
	OR ([OIB] = @OIB AND @OIB is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAmortizacijskaGrupa_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAmortizacijskaGrupa_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAmortizacijskaGrupa_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOSAmortizacijskaGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAmortizacijskaGrupa_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Postotak],
					[Oznaka],
					[RedBr]
				FROM
					[fin].[tblOSAmortizacijskaGrupa]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAmortizacijskaGrupa_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAmortizacijskaGrupa_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAmortizacijskaGrupa_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOSAmortizacijskaGrupa table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAmortizacijskaGrupa_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Postotak]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ' FROM [fin].[tblOSAmortizacijskaGrupa]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Postotak],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [RedBr]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblOSAmortizacijskaGrupa]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAmortizacijskaGrupa_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAmortizacijskaGrupa_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAmortizacijskaGrupa_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOSAmortizacijskaGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAmortizacijskaGrupa_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  ,

	@Postotak real   ,

	@Oznaka nvarchar (50)  ,

	@RedBr int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblOSAmortizacijskaGrupa]
					(
					[Naziv]
					,[Postotak]
					,[Oznaka]
					,[RedBr]
					)
				VALUES
					(
					@Naziv
					,@Postotak
					,@Oznaka
					,@RedBr
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAmortizacijskaGrupa_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAmortizacijskaGrupa_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAmortizacijskaGrupa_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOSAmortizacijskaGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAmortizacijskaGrupa_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  ,

	@Postotak real   ,

	@Oznaka nvarchar (50)  ,

	@RedBr int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblOSAmortizacijskaGrupa]
				SET
					[Naziv] = @Naziv
					,[Postotak] = @Postotak
					,[Oznaka] = @Oznaka
					,[RedBr] = @RedBr
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAmortizacijskaGrupa_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAmortizacijskaGrupa_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAmortizacijskaGrupa_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOSAmortizacijskaGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAmortizacijskaGrupa_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblOSAmortizacijskaGrupa] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAmortizacijskaGrupa_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAmortizacijskaGrupa_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAmortizacijskaGrupa_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSAmortizacijskaGrupa table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAmortizacijskaGrupa_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[Postotak],
					[Oznaka],
					[RedBr]
				FROM
					[fin].[tblOSAmortizacijskaGrupa]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAmortizacijskaGrupa_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAmortizacijskaGrupa_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAmortizacijskaGrupa_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOSAmortizacijskaGrupa table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAmortizacijskaGrupa_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null ,

	@Postotak real   = null ,

	@Oznaka nvarchar (50)  = null ,

	@RedBr int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Postotak]
	, [Oznaka]
	, [RedBr]
    FROM
	[fin].[tblOSAmortizacijskaGrupa]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Postotak] = @Postotak OR @Postotak is null)
	AND ([Oznaka] = @Oznaka OR @Oznaka is null)
	AND ([RedBr] = @RedBr OR @RedBr is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Postotak]
	, [Oznaka]
	, [RedBr]
    FROM
	[fin].[tblOSAmortizacijskaGrupa]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Postotak] = @Postotak AND @Postotak is not null)
	OR ([Oznaka] = @Oznaka AND @Oznaka is not null)
	OR ([RedBr] = @RedBr AND @RedBr is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblOSAGPromjena table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[IDOSGrupa],
					[IDKontoNabave],
					[IDKontoIspravka],
					[IDKontoTroska],
					[IDOSAG],
					[DatumOd],
					[DatumDo]
				FROM
					[fin].[tblOSAGPromjena]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblOSAGPromjena table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOS]'
				SET @SQL = @SQL + ', [IDOSGrupa]'
				SET @SQL = @SQL + ', [IDKontoNabave]'
				SET @SQL = @SQL + ', [IDKontoIspravka]'
				SET @SQL = @SQL + ', [IDKontoTroska]'
				SET @SQL = @SQL + ', [IDOSAG]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ' FROM [fin].[tblOSAGPromjena]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOS],'
				SET @SQL = @SQL + ' [IDOSGrupa],'
				SET @SQL = @SQL + ' [IDKontoNabave],'
				SET @SQL = @SQL + ' [IDKontoIspravka],'
				SET @SQL = @SQL + ' [IDKontoTroska],'
				SET @SQL = @SQL + ' [IDOSAG],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblOSAGPromjena]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblOSAGPromjena table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_Insert
(

	@ID int    OUTPUT,

	@IDOS int   ,

	@IDOSGrupa int   ,

	@IDKontoNabave int   ,

	@IDKontoIspravka int   ,

	@IDKontoTroska int   ,

	@IDOSAG int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblOSAGPromjena]
					(
					[IDOS]
					,[IDOSGrupa]
					,[IDKontoNabave]
					,[IDKontoIspravka]
					,[IDKontoTroska]
					,[IDOSAG]
					,[DatumOd]
					,[DatumDo]
					)
				VALUES
					(
					@IDOS
					,@IDOSGrupa
					,@IDKontoNabave
					,@IDKontoIspravka
					,@IDKontoTroska
					,@IDOSAG
					,@DatumOd
					,@DatumDo
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblOSAGPromjena table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_Update
(

	@ID int   ,

	@IDOS int   ,

	@IDOSGrupa int   ,

	@IDKontoNabave int   ,

	@IDKontoIspravka int   ,

	@IDKontoTroska int   ,

	@IDOSAG int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblOSAGPromjena]
				SET
					[IDOS] = @IDOS
					,[IDOSGrupa] = @IDOSGrupa
					,[IDKontoNabave] = @IDKontoNabave
					,[IDKontoIspravka] = @IDKontoIspravka
					,[IDKontoTroska] = @IDKontoTroska
					,[IDOSAG] = @IDOSAG
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblOSAGPromjena table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblOSAGPromjena] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_GetByIDKontoIspravka procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_GetByIDKontoIspravka') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_GetByIDKontoIspravka
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSAGPromjena table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_GetByIDKontoIspravka
(

	@IDKontoIspravka int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[IDOSGrupa],
					[IDKontoNabave],
					[IDKontoIspravka],
					[IDKontoTroska],
					[IDOSAG],
					[DatumOd],
					[DatumDo]
				FROM
					[fin].[tblOSAGPromjena]
				WHERE
					[IDKontoIspravka] = @IDKontoIspravka
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_GetByIDKontoTroska procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_GetByIDKontoTroska') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_GetByIDKontoTroska
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSAGPromjena table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_GetByIDKontoTroska
(

	@IDKontoTroska int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[IDOSGrupa],
					[IDKontoNabave],
					[IDKontoIspravka],
					[IDKontoTroska],
					[IDOSAG],
					[DatumOd],
					[DatumDo]
				FROM
					[fin].[tblOSAGPromjena]
				WHERE
					[IDKontoTroska] = @IDKontoTroska
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_GetByIDKontoNabave procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_GetByIDKontoNabave') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_GetByIDKontoNabave
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSAGPromjena table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_GetByIDKontoNabave
(

	@IDKontoNabave int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[IDOSGrupa],
					[IDKontoNabave],
					[IDKontoIspravka],
					[IDKontoTroska],
					[IDOSAG],
					[DatumOd],
					[DatumDo]
				FROM
					[fin].[tblOSAGPromjena]
				WHERE
					[IDKontoNabave] = @IDKontoNabave
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_GetByIDOSAG procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_GetByIDOSAG') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_GetByIDOSAG
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSAGPromjena table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_GetByIDOSAG
(

	@IDOSAG int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[IDOSGrupa],
					[IDKontoNabave],
					[IDKontoIspravka],
					[IDKontoTroska],
					[IDOSAG],
					[DatumOd],
					[DatumDo]
				FROM
					[fin].[tblOSAGPromjena]
				WHERE
					[IDOSAG] = @IDOSAG
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_GetByIDOSGrupa procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_GetByIDOSGrupa') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_GetByIDOSGrupa
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSAGPromjena table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_GetByIDOSGrupa
(

	@IDOSGrupa int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[IDOSGrupa],
					[IDKontoNabave],
					[IDKontoIspravka],
					[IDKontoTroska],
					[IDOSAG],
					[DatumOd],
					[DatumDo]
				FROM
					[fin].[tblOSAGPromjena]
				WHERE
					[IDOSGrupa] = @IDOSGrupa
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_GetByIDOS procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_GetByIDOS') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_GetByIDOS
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSAGPromjena table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_GetByIDOS
(

	@IDOS int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOS],
					[IDOSGrupa],
					[IDKontoNabave],
					[IDKontoIspravka],
					[IDKontoTroska],
					[IDOSAG],
					[DatumOd],
					[DatumDo]
				FROM
					[fin].[tblOSAGPromjena]
				WHERE
					[IDOS] = @IDOS
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblOSAGPromjena table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOS],
					[IDOSGrupa],
					[IDKontoNabave],
					[IDKontoIspravka],
					[IDKontoTroska],
					[IDOSAG],
					[DatumOd],
					[DatumDo]
				FROM
					[fin].[tblOSAGPromjena]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblOSAGPromjena_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblOSAGPromjena_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblOSAGPromjena_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblOSAGPromjena table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblOSAGPromjena_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOS int   = null ,

	@IDOSGrupa int   = null ,

	@IDKontoNabave int   = null ,

	@IDKontoIspravka int   = null ,

	@IDKontoTroska int   = null ,

	@IDOSAG int   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOS]
	, [IDOSGrupa]
	, [IDKontoNabave]
	, [IDKontoIspravka]
	, [IDKontoTroska]
	, [IDOSAG]
	, [DatumOd]
	, [DatumDo]
    FROM
	[fin].[tblOSAGPromjena]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOS] = @IDOS OR @IDOS is null)
	AND ([IDOSGrupa] = @IDOSGrupa OR @IDOSGrupa is null)
	AND ([IDKontoNabave] = @IDKontoNabave OR @IDKontoNabave is null)
	AND ([IDKontoIspravka] = @IDKontoIspravka OR @IDKontoIspravka is null)
	AND ([IDKontoTroska] = @IDKontoTroska OR @IDKontoTroska is null)
	AND ([IDOSAG] = @IDOSAG OR @IDOSAG is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOS]
	, [IDOSGrupa]
	, [IDKontoNabave]
	, [IDKontoIspravka]
	, [IDKontoTroska]
	, [IDOSAG]
	, [DatumOd]
	, [DatumDo]
    FROM
	[fin].[tblOSAGPromjena]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOS] = @IDOS AND @IDOS is not null)
	OR ([IDOSGrupa] = @IDOSGrupa AND @IDOSGrupa is not null)
	OR ([IDKontoNabave] = @IDKontoNabave AND @IDKontoNabave is not null)
	OR ([IDKontoIspravka] = @IDKontoIspravka AND @IDKontoIspravka is not null)
	OR ([IDKontoTroska] = @IDKontoTroska AND @IDKontoTroska is not null)
	OR ([IDOSAG] = @IDOSAG AND @IDOSAG is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalog_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalog_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalog_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblPutniNalog table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalog_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Oznaka],
					[IDDjelatnik],
					[Datum],
					[DatumObracuna],
					[Opis],
					[IDStatus],
					[IDBlagajnaStavkaIsplata],
					[IDBlagajnaStavkaStorno],
					[PredvidenoTrajanje],
					[PredvidenoTrajanjeDana],
					[Napomena],
					[IDDjelatnikOdobrio],
					[IzvjestajPutovanja],
					[IDDjelatnikLikvidirao],
					[IDDjelatnikBlagajna],
					[RedBr]
				FROM
					[fin].[tblPutniNalog]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalog_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalog_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalog_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblPutniNalog table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalog_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [IDDjelatnik]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [DatumObracuna]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ', [IDBlagajnaStavkaIsplata]'
				SET @SQL = @SQL + ', [IDBlagajnaStavkaStorno]'
				SET @SQL = @SQL + ', [PredvidenoTrajanje]'
				SET @SQL = @SQL + ', [PredvidenoTrajanjeDana]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [IDDjelatnikOdobrio]'
				SET @SQL = @SQL + ', [IzvjestajPutovanja]'
				SET @SQL = @SQL + ', [IDDjelatnikLikvidirao]'
				SET @SQL = @SQL + ', [IDDjelatnikBlagajna]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ' FROM [fin].[tblPutniNalog]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [IDDjelatnik],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [DatumObracuna],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [IDStatus],'
				SET @SQL = @SQL + ' [IDBlagajnaStavkaIsplata],'
				SET @SQL = @SQL + ' [IDBlagajnaStavkaStorno],'
				SET @SQL = @SQL + ' [PredvidenoTrajanje],'
				SET @SQL = @SQL + ' [PredvidenoTrajanjeDana],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [IDDjelatnikOdobrio],'
				SET @SQL = @SQL + ' [IzvjestajPutovanja],'
				SET @SQL = @SQL + ' [IDDjelatnikLikvidirao],'
				SET @SQL = @SQL + ' [IDDjelatnikBlagajna],'
				SET @SQL = @SQL + ' [RedBr]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblPutniNalog]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalog_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalog_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalog_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblPutniNalog table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalog_Insert
(

	@ID int    OUTPUT,

	@Oznaka nvarchar (50)  ,

	@IDDjelatnik int   ,

	@Datum datetime   ,

	@DatumObracuna datetime   ,

	@Opis nvarchar (MAX)  ,

	@IDStatus int   ,

	@IDBlagajnaStavkaIsplata int   ,

	@IDBlagajnaStavkaStorno int   ,

	@PredvidenoTrajanje nvarchar (150)  ,

	@PredvidenoTrajanjeDana money   ,

	@Napomena nvarchar (MAX)  ,

	@IDDjelatnikOdobrio int   ,

	@IzvjestajPutovanja nvarchar (MAX)  ,

	@IDDjelatnikLikvidirao int   ,

	@IDDjelatnikBlagajna int   ,

	@RedBr int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblPutniNalog]
					(
					[Oznaka]
					,[IDDjelatnik]
					,[Datum]
					,[DatumObracuna]
					,[Opis]
					,[IDStatus]
					,[IDBlagajnaStavkaIsplata]
					,[IDBlagajnaStavkaStorno]
					,[PredvidenoTrajanje]
					,[PredvidenoTrajanjeDana]
					,[Napomena]
					,[IDDjelatnikOdobrio]
					,[IzvjestajPutovanja]
					,[IDDjelatnikLikvidirao]
					,[IDDjelatnikBlagajna]
					,[RedBr]
					)
				VALUES
					(
					@Oznaka
					,@IDDjelatnik
					,@Datum
					,@DatumObracuna
					,@Opis
					,@IDStatus
					,@IDBlagajnaStavkaIsplata
					,@IDBlagajnaStavkaStorno
					,@PredvidenoTrajanje
					,@PredvidenoTrajanjeDana
					,@Napomena
					,@IDDjelatnikOdobrio
					,@IzvjestajPutovanja
					,@IDDjelatnikLikvidirao
					,@IDDjelatnikBlagajna
					,@RedBr
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalog_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalog_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalog_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblPutniNalog table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalog_Update
(

	@ID int   ,

	@Oznaka nvarchar (50)  ,

	@IDDjelatnik int   ,

	@Datum datetime   ,

	@DatumObracuna datetime   ,

	@Opis nvarchar (MAX)  ,

	@IDStatus int   ,

	@IDBlagajnaStavkaIsplata int   ,

	@IDBlagajnaStavkaStorno int   ,

	@PredvidenoTrajanje nvarchar (150)  ,

	@PredvidenoTrajanjeDana money   ,

	@Napomena nvarchar (MAX)  ,

	@IDDjelatnikOdobrio int   ,

	@IzvjestajPutovanja nvarchar (MAX)  ,

	@IDDjelatnikLikvidirao int   ,

	@IDDjelatnikBlagajna int   ,

	@RedBr int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblPutniNalog]
				SET
					[Oznaka] = @Oznaka
					,[IDDjelatnik] = @IDDjelatnik
					,[Datum] = @Datum
					,[DatumObracuna] = @DatumObracuna
					,[Opis] = @Opis
					,[IDStatus] = @IDStatus
					,[IDBlagajnaStavkaIsplata] = @IDBlagajnaStavkaIsplata
					,[IDBlagajnaStavkaStorno] = @IDBlagajnaStavkaStorno
					,[PredvidenoTrajanje] = @PredvidenoTrajanje
					,[PredvidenoTrajanjeDana] = @PredvidenoTrajanjeDana
					,[Napomena] = @Napomena
					,[IDDjelatnikOdobrio] = @IDDjelatnikOdobrio
					,[IzvjestajPutovanja] = @IzvjestajPutovanja
					,[IDDjelatnikLikvidirao] = @IDDjelatnikLikvidirao
					,[IDDjelatnikBlagajna] = @IDDjelatnikBlagajna
					,[RedBr] = @RedBr
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalog_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalog_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalog_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblPutniNalog table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalog_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblPutniNalog] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalog_GetByIDBlagajnaStavkaIsplata procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalog_GetByIDBlagajnaStavkaIsplata') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalog_GetByIDBlagajnaStavkaIsplata
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalog table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalog_GetByIDBlagajnaStavkaIsplata
(

	@IDBlagajnaStavkaIsplata int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Oznaka],
					[IDDjelatnik],
					[Datum],
					[DatumObracuna],
					[Opis],
					[IDStatus],
					[IDBlagajnaStavkaIsplata],
					[IDBlagajnaStavkaStorno],
					[PredvidenoTrajanje],
					[PredvidenoTrajanjeDana],
					[Napomena],
					[IDDjelatnikOdobrio],
					[IzvjestajPutovanja],
					[IDDjelatnikLikvidirao],
					[IDDjelatnikBlagajna],
					[RedBr]
				FROM
					[fin].[tblPutniNalog]
				WHERE
					[IDBlagajnaStavkaIsplata] = @IDBlagajnaStavkaIsplata
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalog_GetByIDDjelatnik procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalog_GetByIDDjelatnik') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalog_GetByIDDjelatnik
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalog table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalog_GetByIDDjelatnik
(

	@IDDjelatnik int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Oznaka],
					[IDDjelatnik],
					[Datum],
					[DatumObracuna],
					[Opis],
					[IDStatus],
					[IDBlagajnaStavkaIsplata],
					[IDBlagajnaStavkaStorno],
					[PredvidenoTrajanje],
					[PredvidenoTrajanjeDana],
					[Napomena],
					[IDDjelatnikOdobrio],
					[IzvjestajPutovanja],
					[IDDjelatnikLikvidirao],
					[IDDjelatnikBlagajna],
					[RedBr]
				FROM
					[fin].[tblPutniNalog]
				WHERE
					[IDDjelatnik] = @IDDjelatnik
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalog_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalog_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalog_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalog table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalog_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Oznaka],
					[IDDjelatnik],
					[Datum],
					[DatumObracuna],
					[Opis],
					[IDStatus],
					[IDBlagajnaStavkaIsplata],
					[IDBlagajnaStavkaStorno],
					[PredvidenoTrajanje],
					[PredvidenoTrajanjeDana],
					[Napomena],
					[IDDjelatnikOdobrio],
					[IzvjestajPutovanja],
					[IDDjelatnikLikvidirao],
					[IDDjelatnikBlagajna],
					[RedBr]
				FROM
					[fin].[tblPutniNalog]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalog_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalog_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalog_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblPutniNalog table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalog_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Oznaka nvarchar (50)  = null ,

	@IDDjelatnik int   = null ,

	@Datum datetime   = null ,

	@DatumObracuna datetime   = null ,

	@Opis nvarchar (MAX)  = null ,

	@IDStatus int   = null ,

	@IDBlagajnaStavkaIsplata int   = null ,

	@IDBlagajnaStavkaStorno int   = null ,

	@PredvidenoTrajanje nvarchar (150)  = null ,

	@PredvidenoTrajanjeDana money   = null ,

	@Napomena nvarchar (MAX)  = null ,

	@IDDjelatnikOdobrio int   = null ,

	@IzvjestajPutovanja nvarchar (MAX)  = null ,

	@IDDjelatnikLikvidirao int   = null ,

	@IDDjelatnikBlagajna int   = null ,

	@RedBr int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Oznaka]
	, [IDDjelatnik]
	, [Datum]
	, [DatumObracuna]
	, [Opis]
	, [IDStatus]
	, [IDBlagajnaStavkaIsplata]
	, [IDBlagajnaStavkaStorno]
	, [PredvidenoTrajanje]
	, [PredvidenoTrajanjeDana]
	, [Napomena]
	, [IDDjelatnikOdobrio]
	, [IzvjestajPutovanja]
	, [IDDjelatnikLikvidirao]
	, [IDDjelatnikBlagajna]
	, [RedBr]
    FROM
	[fin].[tblPutniNalog]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Oznaka] = @Oznaka OR @Oznaka is null)
	AND ([IDDjelatnik] = @IDDjelatnik OR @IDDjelatnik is null)
	AND ([Datum] = @Datum OR @Datum is null)
	AND ([DatumObracuna] = @DatumObracuna OR @DatumObracuna is null)
	AND ([Opis] = @Opis OR @Opis is null)
	AND ([IDStatus] = @IDStatus OR @IDStatus is null)
	AND ([IDBlagajnaStavkaIsplata] = @IDBlagajnaStavkaIsplata OR @IDBlagajnaStavkaIsplata is null)
	AND ([IDBlagajnaStavkaStorno] = @IDBlagajnaStavkaStorno OR @IDBlagajnaStavkaStorno is null)
	AND ([PredvidenoTrajanje] = @PredvidenoTrajanje OR @PredvidenoTrajanje is null)
	AND ([PredvidenoTrajanjeDana] = @PredvidenoTrajanjeDana OR @PredvidenoTrajanjeDana is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([IDDjelatnikOdobrio] = @IDDjelatnikOdobrio OR @IDDjelatnikOdobrio is null)
	AND ([IzvjestajPutovanja] = @IzvjestajPutovanja OR @IzvjestajPutovanja is null)
	AND ([IDDjelatnikLikvidirao] = @IDDjelatnikLikvidirao OR @IDDjelatnikLikvidirao is null)
	AND ([IDDjelatnikBlagajna] = @IDDjelatnikBlagajna OR @IDDjelatnikBlagajna is null)
	AND ([RedBr] = @RedBr OR @RedBr is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Oznaka]
	, [IDDjelatnik]
	, [Datum]
	, [DatumObracuna]
	, [Opis]
	, [IDStatus]
	, [IDBlagajnaStavkaIsplata]
	, [IDBlagajnaStavkaStorno]
	, [PredvidenoTrajanje]
	, [PredvidenoTrajanjeDana]
	, [Napomena]
	, [IDDjelatnikOdobrio]
	, [IzvjestajPutovanja]
	, [IDDjelatnikLikvidirao]
	, [IDDjelatnikBlagajna]
	, [RedBr]
    FROM
	[fin].[tblPutniNalog]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Oznaka] = @Oznaka AND @Oznaka is not null)
	OR ([IDDjelatnik] = @IDDjelatnik AND @IDDjelatnik is not null)
	OR ([Datum] = @Datum AND @Datum is not null)
	OR ([DatumObracuna] = @DatumObracuna AND @DatumObracuna is not null)
	OR ([Opis] = @Opis AND @Opis is not null)
	OR ([IDStatus] = @IDStatus AND @IDStatus is not null)
	OR ([IDBlagajnaStavkaIsplata] = @IDBlagajnaStavkaIsplata AND @IDBlagajnaStavkaIsplata is not null)
	OR ([IDBlagajnaStavkaStorno] = @IDBlagajnaStavkaStorno AND @IDBlagajnaStavkaStorno is not null)
	OR ([PredvidenoTrajanje] = @PredvidenoTrajanje AND @PredvidenoTrajanje is not null)
	OR ([PredvidenoTrajanjeDana] = @PredvidenoTrajanjeDana AND @PredvidenoTrajanjeDana is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([IDDjelatnikOdobrio] = @IDDjelatnikOdobrio AND @IDDjelatnikOdobrio is not null)
	OR ([IzvjestajPutovanja] = @IzvjestajPutovanja AND @IzvjestajPutovanja is not null)
	OR ([IDDjelatnikLikvidirao] = @IDDjelatnikLikvidirao AND @IDDjelatnikLikvidirao is not null)
	OR ([IDDjelatnikBlagajna] = @IDDjelatnikBlagajna AND @IDDjelatnikBlagajna is not null)
	OR ([RedBr] = @RedBr AND @RedBr is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogAkontacija_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogAkontacija_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogAkontacija_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblPutniNalogAkontacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogAkontacija_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[IDValuta],
					[IznosValuta],
					[IznosKuna],
					[Slovima],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogAkontacija]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogAkontacija_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogAkontacija_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogAkontacija_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblPutniNalogAkontacija table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogAkontacija_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDPutniNalog]'
				SET @SQL = @SQL + ', [IDValuta]'
				SET @SQL = @SQL + ', [IznosValuta]'
				SET @SQL = @SQL + ', [IznosKuna]'
				SET @SQL = @SQL + ', [Slovima]'
				SET @SQL = @SQL + ', [IDBlagajnaStavka]'
				SET @SQL = @SQL + ' FROM [fin].[tblPutniNalogAkontacija]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDPutniNalog],'
				SET @SQL = @SQL + ' [IDValuta],'
				SET @SQL = @SQL + ' [IznosValuta],'
				SET @SQL = @SQL + ' [IznosKuna],'
				SET @SQL = @SQL + ' [Slovima],'
				SET @SQL = @SQL + ' [IDBlagajnaStavka]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblPutniNalogAkontacija]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogAkontacija_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogAkontacija_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogAkontacija_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblPutniNalogAkontacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogAkontacija_Insert
(

	@ID int    OUTPUT,

	@IDPutniNalog int   ,

	@IDValuta int   ,

	@IznosValuta money   ,

	@IznosKuna money   ,

	@Slovima nvarchar (150)  ,

	@IDBlagajnaStavka int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblPutniNalogAkontacija]
					(
					[IDPutniNalog]
					,[IDValuta]
					,[IznosValuta]
					,[IznosKuna]
					,[Slovima]
					,[IDBlagajnaStavka]
					)
				VALUES
					(
					@IDPutniNalog
					,@IDValuta
					,@IznosValuta
					,@IznosKuna
					,@Slovima
					,@IDBlagajnaStavka
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogAkontacija_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogAkontacija_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogAkontacija_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblPutniNalogAkontacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogAkontacija_Update
(

	@ID int   ,

	@IDPutniNalog int   ,

	@IDValuta int   ,

	@IznosValuta money   ,

	@IznosKuna money   ,

	@Slovima nvarchar (150)  ,

	@IDBlagajnaStavka int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblPutniNalogAkontacija]
				SET
					[IDPutniNalog] = @IDPutniNalog
					,[IDValuta] = @IDValuta
					,[IznosValuta] = @IznosValuta
					,[IznosKuna] = @IznosKuna
					,[Slovima] = @Slovima
					,[IDBlagajnaStavka] = @IDBlagajnaStavka
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogAkontacija_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogAkontacija_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogAkontacija_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblPutniNalogAkontacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogAkontacija_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblPutniNalogAkontacija] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogAkontacija_GetByIDBlagajnaStavka procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogAkontacija_GetByIDBlagajnaStavka') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogAkontacija_GetByIDBlagajnaStavka
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogAkontacija table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogAkontacija_GetByIDBlagajnaStavka
(

	@IDBlagajnaStavka int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[IDValuta],
					[IznosValuta],
					[IznosKuna],
					[Slovima],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogAkontacija]
				WHERE
					[IDBlagajnaStavka] = @IDBlagajnaStavka
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogAkontacija_GetByIDPutniNalog procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogAkontacija_GetByIDPutniNalog') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogAkontacija_GetByIDPutniNalog
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogAkontacija table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogAkontacija_GetByIDPutniNalog
(

	@IDPutniNalog int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[IDValuta],
					[IznosValuta],
					[IznosKuna],
					[Slovima],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogAkontacija]
				WHERE
					[IDPutniNalog] = @IDPutniNalog
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogAkontacija_GetByIDValuta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogAkontacija_GetByIDValuta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogAkontacija_GetByIDValuta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogAkontacija table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogAkontacija_GetByIDValuta
(

	@IDValuta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[IDValuta],
					[IznosValuta],
					[IznosKuna],
					[Slovima],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogAkontacija]
				WHERE
					[IDValuta] = @IDValuta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogAkontacija_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogAkontacija_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogAkontacija_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogAkontacija table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogAkontacija_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDPutniNalog],
					[IDValuta],
					[IznosValuta],
					[IznosKuna],
					[Slovima],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogAkontacija]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogAkontacija_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogAkontacija_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogAkontacija_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblPutniNalogAkontacija table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogAkontacija_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDPutniNalog int   = null ,

	@IDValuta int   = null ,

	@IznosValuta money   = null ,

	@IznosKuna money   = null ,

	@Slovima nvarchar (150)  = null ,

	@IDBlagajnaStavka int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDPutniNalog]
	, [IDValuta]
	, [IznosValuta]
	, [IznosKuna]
	, [Slovima]
	, [IDBlagajnaStavka]
    FROM
	[fin].[tblPutniNalogAkontacija]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDPutniNalog] = @IDPutniNalog OR @IDPutniNalog is null)
	AND ([IDValuta] = @IDValuta OR @IDValuta is null)
	AND ([IznosValuta] = @IznosValuta OR @IznosValuta is null)
	AND ([IznosKuna] = @IznosKuna OR @IznosKuna is null)
	AND ([Slovima] = @Slovima OR @Slovima is null)
	AND ([IDBlagajnaStavka] = @IDBlagajnaStavka OR @IDBlagajnaStavka is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDPutniNalog]
	, [IDValuta]
	, [IznosValuta]
	, [IznosKuna]
	, [Slovima]
	, [IDBlagajnaStavka]
    FROM
	[fin].[tblPutniNalogAkontacija]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDPutniNalog] = @IDPutniNalog AND @IDPutniNalog is not null)
	OR ([IDValuta] = @IDValuta AND @IDValuta is not null)
	OR ([IznosValuta] = @IznosValuta AND @IznosValuta is not null)
	OR ([IznosKuna] = @IznosKuna AND @IznosKuna is not null)
	OR ([Slovima] = @Slovima AND @Slovima is not null)
	OR ([IDBlagajnaStavka] = @IDBlagajnaStavka AND @IDBlagajnaStavka is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblValuta_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblValuta_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblValuta_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblValuta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblValuta_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Kratica],
					[Sifra],
					[Kolicina]
				FROM
					[dbo].[tblValuta]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblValuta_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblValuta_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblValuta_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblValuta table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblValuta_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Kratica]'
				SET @SQL = @SQL + ', [Sifra]'
				SET @SQL = @SQL + ', [Kolicina]'
				SET @SQL = @SQL + ' FROM [dbo].[tblValuta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Kratica],'
				SET @SQL = @SQL + ' [Sifra],'
				SET @SQL = @SQL + ' [Kolicina]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblValuta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblValuta_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblValuta_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblValuta_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblValuta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblValuta_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  ,

	@Kratica nvarchar (5)  ,

	@Sifra int   ,

	@Kolicina int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblValuta]
					(
					[Naziv]
					,[Kratica]
					,[Sifra]
					,[Kolicina]
					)
				VALUES
					(
					@Naziv
					,@Kratica
					,@Sifra
					,@Kolicina
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblValuta_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblValuta_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblValuta_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblValuta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblValuta_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  ,

	@Kratica nvarchar (5)  ,

	@Sifra int   ,

	@Kolicina int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblValuta]
				SET
					[Naziv] = @Naziv
					,[Kratica] = @Kratica
					,[Sifra] = @Sifra
					,[Kolicina] = @Kolicina
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblValuta_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblValuta_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblValuta_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblValuta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblValuta_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblValuta] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblValuta_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblValuta_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblValuta_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblValuta table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblValuta_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[Kratica],
					[Sifra],
					[Kolicina]
				FROM
					[dbo].[tblValuta]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblValuta_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblValuta_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblValuta_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblValuta table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblValuta_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null ,

	@Kratica nvarchar (5)  = null ,

	@Sifra int   = null ,

	@Kolicina int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Kratica]
	, [Sifra]
	, [Kolicina]
    FROM
	[dbo].[tblValuta]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Kratica] = @Kratica OR @Kratica is null)
	AND ([Sifra] = @Sifra OR @Sifra is null)
	AND ([Kolicina] = @Kolicina OR @Kolicina is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Kratica]
	, [Sifra]
	, [Kolicina]
    FROM
	[dbo].[tblValuta]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Kratica] = @Kratica AND @Kratica is not null)
	OR ([Sifra] = @Sifra AND @Sifra is not null)
	OR ([Kolicina] = @Kolicina AND @Kolicina is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaDnevnica_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaDnevnica_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaDnevnica_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblPutniNalogStavkaDnevnica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaDnevnica_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[Pocetak],
					[Kraj],
					[IDDnevnica],
					[DnevnicaIznos],
					[OdobreniPostotakDnevnice],
					[Iznos],
					[IDKontoDnevnice],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaDnevnica]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaDnevnica_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaDnevnica_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaDnevnica_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblPutniNalogStavkaDnevnica table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaDnevnica_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDPutniNalog]'
				SET @SQL = @SQL + ', [Pocetak]'
				SET @SQL = @SQL + ', [Kraj]'
				SET @SQL = @SQL + ', [IDDnevnica]'
				SET @SQL = @SQL + ', [DnevnicaIznos]'
				SET @SQL = @SQL + ', [OdobreniPostotakDnevnice]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [IDKontoDnevnice]'
				SET @SQL = @SQL + ', [IDBlagajnaStavka]'
				SET @SQL = @SQL + ' FROM [fin].[tblPutniNalogStavkaDnevnica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDPutniNalog],'
				SET @SQL = @SQL + ' [Pocetak],'
				SET @SQL = @SQL + ' [Kraj],'
				SET @SQL = @SQL + ' [IDDnevnica],'
				SET @SQL = @SQL + ' [DnevnicaIznos],'
				SET @SQL = @SQL + ' [OdobreniPostotakDnevnice],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [IDKontoDnevnice],'
				SET @SQL = @SQL + ' [IDBlagajnaStavka]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblPutniNalogStavkaDnevnica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaDnevnica_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaDnevnica_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaDnevnica_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblPutniNalogStavkaDnevnica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaDnevnica_Insert
(

	@ID int    OUTPUT,

	@IDPutniNalog int   ,

	@Pocetak datetime   ,

	@Kraj datetime   ,

	@IDDnevnica int   ,

	@DnevnicaIznos money   ,

	@OdobreniPostotakDnevnice money   ,

	@Iznos money   ,

	@IDKontoDnevnice int   ,

	@IDBlagajnaStavka int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblPutniNalogStavkaDnevnica]
					(
					[IDPutniNalog]
					,[Pocetak]
					,[Kraj]
					,[IDDnevnica]
					,[DnevnicaIznos]
					,[OdobreniPostotakDnevnice]
					,[Iznos]
					,[IDKontoDnevnice]
					,[IDBlagajnaStavka]
					)
				VALUES
					(
					@IDPutniNalog
					,@Pocetak
					,@Kraj
					,@IDDnevnica
					,@DnevnicaIznos
					,@OdobreniPostotakDnevnice
					,@Iznos
					,@IDKontoDnevnice
					,@IDBlagajnaStavka
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaDnevnica_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaDnevnica_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaDnevnica_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblPutniNalogStavkaDnevnica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaDnevnica_Update
(

	@ID int   ,

	@IDPutniNalog int   ,

	@Pocetak datetime   ,

	@Kraj datetime   ,

	@IDDnevnica int   ,

	@DnevnicaIznos money   ,

	@OdobreniPostotakDnevnice money   ,

	@Iznos money   ,

	@IDKontoDnevnice int   ,

	@IDBlagajnaStavka int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblPutniNalogStavkaDnevnica]
				SET
					[IDPutniNalog] = @IDPutniNalog
					,[Pocetak] = @Pocetak
					,[Kraj] = @Kraj
					,[IDDnevnica] = @IDDnevnica
					,[DnevnicaIznos] = @DnevnicaIznos
					,[OdobreniPostotakDnevnice] = @OdobreniPostotakDnevnice
					,[Iznos] = @Iznos
					,[IDKontoDnevnice] = @IDKontoDnevnice
					,[IDBlagajnaStavka] = @IDBlagajnaStavka
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaDnevnica_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaDnevnica_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaDnevnica_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblPutniNalogStavkaDnevnica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaDnevnica_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblPutniNalogStavkaDnevnica] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaDnevnica_GetByIDDnevnica procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaDnevnica_GetByIDDnevnica') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaDnevnica_GetByIDDnevnica
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaDnevnica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaDnevnica_GetByIDDnevnica
(

	@IDDnevnica int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[Pocetak],
					[Kraj],
					[IDDnevnica],
					[DnevnicaIznos],
					[OdobreniPostotakDnevnice],
					[Iznos],
					[IDKontoDnevnice],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaDnevnica]
				WHERE
					[IDDnevnica] = @IDDnevnica
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaDnevnica_GetByIDKontoDnevnice procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaDnevnica_GetByIDKontoDnevnice') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaDnevnica_GetByIDKontoDnevnice
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaDnevnica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaDnevnica_GetByIDKontoDnevnice
(

	@IDKontoDnevnice int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[Pocetak],
					[Kraj],
					[IDDnevnica],
					[DnevnicaIznos],
					[OdobreniPostotakDnevnice],
					[Iznos],
					[IDKontoDnevnice],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaDnevnica]
				WHERE
					[IDKontoDnevnice] = @IDKontoDnevnice
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaDnevnica_GetByIDPutniNalog procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaDnevnica_GetByIDPutniNalog') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaDnevnica_GetByIDPutniNalog
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaDnevnica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaDnevnica_GetByIDPutniNalog
(

	@IDPutniNalog int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[Pocetak],
					[Kraj],
					[IDDnevnica],
					[DnevnicaIznos],
					[OdobreniPostotakDnevnice],
					[Iznos],
					[IDKontoDnevnice],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaDnevnica]
				WHERE
					[IDPutniNalog] = @IDPutniNalog
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaDnevnica_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaDnevnica_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaDnevnica_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaDnevnica table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaDnevnica_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDPutniNalog],
					[Pocetak],
					[Kraj],
					[IDDnevnica],
					[DnevnicaIznos],
					[OdobreniPostotakDnevnice],
					[Iznos],
					[IDKontoDnevnice],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaDnevnica]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaDnevnica_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaDnevnica_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaDnevnica_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblPutniNalogStavkaDnevnica table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaDnevnica_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDPutniNalog int   = null ,

	@Pocetak datetime   = null ,

	@Kraj datetime   = null ,

	@IDDnevnica int   = null ,

	@DnevnicaIznos money   = null ,

	@OdobreniPostotakDnevnice money   = null ,

	@Iznos money   = null ,

	@IDKontoDnevnice int   = null ,

	@IDBlagajnaStavka int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDPutniNalog]
	, [Pocetak]
	, [Kraj]
	, [IDDnevnica]
	, [DnevnicaIznos]
	, [OdobreniPostotakDnevnice]
	, [Iznos]
	, [IDKontoDnevnice]
	, [IDBlagajnaStavka]
    FROM
	[fin].[tblPutniNalogStavkaDnevnica]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDPutniNalog] = @IDPutniNalog OR @IDPutniNalog is null)
	AND ([Pocetak] = @Pocetak OR @Pocetak is null)
	AND ([Kraj] = @Kraj OR @Kraj is null)
	AND ([IDDnevnica] = @IDDnevnica OR @IDDnevnica is null)
	AND ([DnevnicaIznos] = @DnevnicaIznos OR @DnevnicaIznos is null)
	AND ([OdobreniPostotakDnevnice] = @OdobreniPostotakDnevnice OR @OdobreniPostotakDnevnice is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
	AND ([IDKontoDnevnice] = @IDKontoDnevnice OR @IDKontoDnevnice is null)
	AND ([IDBlagajnaStavka] = @IDBlagajnaStavka OR @IDBlagajnaStavka is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDPutniNalog]
	, [Pocetak]
	, [Kraj]
	, [IDDnevnica]
	, [DnevnicaIznos]
	, [OdobreniPostotakDnevnice]
	, [Iznos]
	, [IDKontoDnevnice]
	, [IDBlagajnaStavka]
    FROM
	[fin].[tblPutniNalogStavkaDnevnica]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDPutniNalog] = @IDPutniNalog AND @IDPutniNalog is not null)
	OR ([Pocetak] = @Pocetak AND @Pocetak is not null)
	OR ([Kraj] = @Kraj AND @Kraj is not null)
	OR ([IDDnevnica] = @IDDnevnica AND @IDDnevnica is not null)
	OR ([DnevnicaIznos] = @DnevnicaIznos AND @DnevnicaIznos is not null)
	OR ([OdobreniPostotakDnevnice] = @OdobreniPostotakDnevnice AND @OdobreniPostotakDnevnice is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	OR ([IDKontoDnevnice] = @IDKontoDnevnice AND @IDKontoDnevnice is not null)
	OR ([IDBlagajnaStavka] = @IDBlagajnaStavka AND @IDBlagajnaStavka is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReport_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReport_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReport_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblReport table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReport_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDParent],
					[SelectString],
					[Tip],
					[Kolumne],
					[Filter],
					[FilterAdv],
					[Poredak]
				FROM
					[dbo].[tblReport]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReport_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReport_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReport_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblReport table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReport_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [IDParent]'
				SET @SQL = @SQL + ', [SelectString]'
				SET @SQL = @SQL + ', [Tip]'
				SET @SQL = @SQL + ', [Kolumne]'
				SET @SQL = @SQL + ', [Filter]'
				SET @SQL = @SQL + ', [FilterAdv]'
				SET @SQL = @SQL + ', [Poredak]'
				SET @SQL = @SQL + ' FROM [dbo].[tblReport]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [IDParent],'
				SET @SQL = @SQL + ' [SelectString],'
				SET @SQL = @SQL + ' [Tip],'
				SET @SQL = @SQL + ' [Kolumne],'
				SET @SQL = @SQL + ' [Filter],'
				SET @SQL = @SQL + ' [FilterAdv],'
				SET @SQL = @SQL + ' [Poredak]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblReport]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReport_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReport_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReport_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblReport table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReport_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (200)  ,

	@IDParent int   ,

	@SelectString nvarchar (MAX)  ,

	@Tip int   ,

	@Kolumne nvarchar (300)  ,

	@Filter varbinary (MAX)  ,

	@FilterAdv varbinary (MAX)  ,

	@Poredak nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblReport]
					(
					[Naziv]
					,[IDParent]
					,[SelectString]
					,[Tip]
					,[Kolumne]
					,[Filter]
					,[FilterAdv]
					,[Poredak]
					)
				VALUES
					(
					@Naziv
					,@IDParent
					,@SelectString
					,@Tip
					,@Kolumne
					,@Filter
					,@FilterAdv
					,@Poredak
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReport_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReport_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReport_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblReport table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReport_Update
(

	@ID int   ,

	@Naziv nvarchar (200)  ,

	@IDParent int   ,

	@SelectString nvarchar (MAX)  ,

	@Tip int   ,

	@Kolumne nvarchar (300)  ,

	@Filter varbinary (MAX)  ,

	@FilterAdv varbinary (MAX)  ,

	@Poredak nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblReport]
				SET
					[Naziv] = @Naziv
					,[IDParent] = @IDParent
					,[SelectString] = @SelectString
					,[Tip] = @Tip
					,[Kolumne] = @Kolumne
					,[Filter] = @Filter
					,[FilterAdv] = @FilterAdv
					,[Poredak] = @Poredak
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReport_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReport_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReport_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblReport table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReport_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblReport] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReport_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReport_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReport_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReport table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReport_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[IDParent],
					[SelectString],
					[Tip],
					[Kolumne],
					[Filter],
					[FilterAdv],
					[Poredak]
				FROM
					[dbo].[tblReport]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReport_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReport_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReport_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblReport table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReport_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (200)  = null ,

	@IDParent int   = null ,

	@SelectString nvarchar (MAX)  = null ,

	@Tip int   = null ,

	@Kolumne nvarchar (300)  = null ,

	@Filter varbinary (MAX)  = null ,

	@FilterAdv varbinary (MAX)  = null ,

	@Poredak nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [IDParent]
	, [SelectString]
	, [Tip]
	, [Kolumne]
	, [Filter]
	, [FilterAdv]
	, [Poredak]
    FROM
	[dbo].[tblReport]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([IDParent] = @IDParent OR @IDParent is null)
	AND ([SelectString] = @SelectString OR @SelectString is null)
	AND ([Tip] = @Tip OR @Tip is null)
	AND ([Kolumne] = @Kolumne OR @Kolumne is null)
	AND ([Poredak] = @Poredak OR @Poredak is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [IDParent]
	, [SelectString]
	, [Tip]
	, [Kolumne]
	, [Filter]
	, [FilterAdv]
	, [Poredak]
    FROM
	[dbo].[tblReport]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([IDParent] = @IDParent AND @IDParent is not null)
	OR ([SelectString] = @SelectString AND @SelectString is not null)
	OR ([Tip] = @Tip AND @Tip is not null)
	OR ([Kolumne] = @Kolumne AND @Kolumne is not null)
	OR ([Poredak] = @Poredak AND @Poredak is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtijevStavke_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtijevStavke_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtijevStavke_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblSklDZahtijevStavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtijevStavke_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDSklDZahtjevGlava],
					[SifraArtikla],
					[NazivArtikla],
					[Batch],
					[NettoMasa],
					[Kolicina],
					[Cijena],
					[Valuta],
					[Porijeklo],
					[DateUIModified]
				FROM
					[dbo].[tblSklDZahtijevStavke]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtijevStavke_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtijevStavke_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtijevStavke_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblSklDZahtijevStavke table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtijevStavke_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDSklDZahtjevGlava]'
				SET @SQL = @SQL + ', [SifraArtikla]'
				SET @SQL = @SQL + ', [NazivArtikla]'
				SET @SQL = @SQL + ', [Batch]'
				SET @SQL = @SQL + ', [NettoMasa]'
				SET @SQL = @SQL + ', [Kolicina]'
				SET @SQL = @SQL + ', [Cijena]'
				SET @SQL = @SQL + ', [Valuta]'
				SET @SQL = @SQL + ', [Porijeklo]'
				SET @SQL = @SQL + ', [DateUIModified]'
				SET @SQL = @SQL + ' FROM [dbo].[tblSklDZahtijevStavke]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDSklDZahtjevGlava],'
				SET @SQL = @SQL + ' [SifraArtikla],'
				SET @SQL = @SQL + ' [NazivArtikla],'
				SET @SQL = @SQL + ' [Batch],'
				SET @SQL = @SQL + ' [NettoMasa],'
				SET @SQL = @SQL + ' [Kolicina],'
				SET @SQL = @SQL + ' [Cijena],'
				SET @SQL = @SQL + ' [Valuta],'
				SET @SQL = @SQL + ' [Porijeklo],'
				SET @SQL = @SQL + ' [DateUIModified]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblSklDZahtijevStavke]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtijevStavke_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtijevStavke_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtijevStavke_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblSklDZahtijevStavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtijevStavke_Insert
(

	@ID int    OUTPUT,

	@IDSklDZahtjevGlava int   ,

	@SifraArtikla int   ,

	@NazivArtikla nvarchar (250)  ,

	@Batch nvarchar (250)  ,

	@NettoMasa money   ,

	@Kolicina money   ,

	@Cijena money   ,

	@Valuta nvarchar (50)  ,

	@Porijeklo nvarchar (250)  ,

	@DateUIModified datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblSklDZahtijevStavke]
					(
					[IDSklDZahtjevGlava]
					,[SifraArtikla]
					,[NazivArtikla]
					,[Batch]
					,[NettoMasa]
					,[Kolicina]
					,[Cijena]
					,[Valuta]
					,[Porijeklo]
					,[DateUIModified]
					)
				VALUES
					(
					@IDSklDZahtjevGlava
					,@SifraArtikla
					,@NazivArtikla
					,@Batch
					,@NettoMasa
					,@Kolicina
					,@Cijena
					,@Valuta
					,@Porijeklo
					,@DateUIModified
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtijevStavke_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtijevStavke_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtijevStavke_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblSklDZahtijevStavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtijevStavke_Update
(

	@ID int   ,

	@IDSklDZahtjevGlava int   ,

	@SifraArtikla int   ,

	@NazivArtikla nvarchar (250)  ,

	@Batch nvarchar (250)  ,

	@NettoMasa money   ,

	@Kolicina money   ,

	@Cijena money   ,

	@Valuta nvarchar (50)  ,

	@Porijeklo nvarchar (250)  ,

	@DateUIModified datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblSklDZahtijevStavke]
				SET
					[IDSklDZahtjevGlava] = @IDSklDZahtjevGlava
					,[SifraArtikla] = @SifraArtikla
					,[NazivArtikla] = @NazivArtikla
					,[Batch] = @Batch
					,[NettoMasa] = @NettoMasa
					,[Kolicina] = @Kolicina
					,[Cijena] = @Cijena
					,[Valuta] = @Valuta
					,[Porijeklo] = @Porijeklo
					,[DateUIModified] = @DateUIModified
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtijevStavke_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtijevStavke_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtijevStavke_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblSklDZahtijevStavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtijevStavke_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblSklDZahtijevStavke] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtijevStavke_GetByIDSklDZahtjevGlava procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtijevStavke_GetByIDSklDZahtjevGlava') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtijevStavke_GetByIDSklDZahtjevGlava
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblSklDZahtijevStavke table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtijevStavke_GetByIDSklDZahtjevGlava
(

	@IDSklDZahtjevGlava int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDSklDZahtjevGlava],
					[SifraArtikla],
					[NazivArtikla],
					[Batch],
					[NettoMasa],
					[Kolicina],
					[Cijena],
					[Valuta],
					[Porijeklo],
					[DateUIModified]
				FROM
					[dbo].[tblSklDZahtijevStavke]
				WHERE
					[IDSklDZahtjevGlava] = @IDSklDZahtjevGlava
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtijevStavke_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtijevStavke_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtijevStavke_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblSklDZahtijevStavke table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtijevStavke_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDSklDZahtjevGlava],
					[SifraArtikla],
					[NazivArtikla],
					[Batch],
					[NettoMasa],
					[Kolicina],
					[Cijena],
					[Valuta],
					[Porijeklo],
					[DateUIModified]
				FROM
					[dbo].[tblSklDZahtijevStavke]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtijevStavke_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtijevStavke_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtijevStavke_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblSklDZahtijevStavke table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtijevStavke_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDSklDZahtjevGlava int   = null ,

	@SifraArtikla int   = null ,

	@NazivArtikla nvarchar (250)  = null ,

	@Batch nvarchar (250)  = null ,

	@NettoMasa money   = null ,

	@Kolicina money   = null ,

	@Cijena money   = null ,

	@Valuta nvarchar (50)  = null ,

	@Porijeklo nvarchar (250)  = null ,

	@DateUIModified datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDSklDZahtjevGlava]
	, [SifraArtikla]
	, [NazivArtikla]
	, [Batch]
	, [NettoMasa]
	, [Kolicina]
	, [Cijena]
	, [Valuta]
	, [Porijeklo]
	, [DateUIModified]
    FROM
	[dbo].[tblSklDZahtijevStavke]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDSklDZahtjevGlava] = @IDSklDZahtjevGlava OR @IDSklDZahtjevGlava is null)
	AND ([SifraArtikla] = @SifraArtikla OR @SifraArtikla is null)
	AND ([NazivArtikla] = @NazivArtikla OR @NazivArtikla is null)
	AND ([Batch] = @Batch OR @Batch is null)
	AND ([NettoMasa] = @NettoMasa OR @NettoMasa is null)
	AND ([Kolicina] = @Kolicina OR @Kolicina is null)
	AND ([Cijena] = @Cijena OR @Cijena is null)
	AND ([Valuta] = @Valuta OR @Valuta is null)
	AND ([Porijeklo] = @Porijeklo OR @Porijeklo is null)
	AND ([DateUIModified] = @DateUIModified OR @DateUIModified is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDSklDZahtjevGlava]
	, [SifraArtikla]
	, [NazivArtikla]
	, [Batch]
	, [NettoMasa]
	, [Kolicina]
	, [Cijena]
	, [Valuta]
	, [Porijeklo]
	, [DateUIModified]
    FROM
	[dbo].[tblSklDZahtijevStavke]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDSklDZahtjevGlava] = @IDSklDZahtjevGlava AND @IDSklDZahtjevGlava is not null)
	OR ([SifraArtikla] = @SifraArtikla AND @SifraArtikla is not null)
	OR ([NazivArtikla] = @NazivArtikla AND @NazivArtikla is not null)
	OR ([Batch] = @Batch AND @Batch is not null)
	OR ([NettoMasa] = @NettoMasa AND @NettoMasa is not null)
	OR ([Kolicina] = @Kolicina AND @Kolicina is not null)
	OR ([Cijena] = @Cijena AND @Cijena is not null)
	OR ([Valuta] = @Valuta AND @Valuta is not null)
	OR ([Porijeklo] = @Porijeklo AND @Porijeklo is not null)
	OR ([DateUIModified] = @DateUIModified AND @DateUIModified is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDLager_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDLager_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDLager_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblSklDLager table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDLager_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[SifraArtikla],
					[NazivArtikla],
					[Batch],
					[NettoMasa],
					[Kolicina],
					[Cijena],
					[Valuta],
					[Porijeklo]
				FROM
					[dbo].[tblSklDLager]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDLager_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDLager_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDLager_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblSklDLager table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDLager_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [SifraArtikla]'
				SET @SQL = @SQL + ', [NazivArtikla]'
				SET @SQL = @SQL + ', [Batch]'
				SET @SQL = @SQL + ', [NettoMasa]'
				SET @SQL = @SQL + ', [Kolicina]'
				SET @SQL = @SQL + ', [Cijena]'
				SET @SQL = @SQL + ', [Valuta]'
				SET @SQL = @SQL + ', [Porijeklo]'
				SET @SQL = @SQL + ' FROM [dbo].[tblSklDLager]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [SifraArtikla],'
				SET @SQL = @SQL + ' [NazivArtikla],'
				SET @SQL = @SQL + ' [Batch],'
				SET @SQL = @SQL + ' [NettoMasa],'
				SET @SQL = @SQL + ' [Kolicina],'
				SET @SQL = @SQL + ' [Cijena],'
				SET @SQL = @SQL + ' [Valuta],'
				SET @SQL = @SQL + ' [Porijeklo]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblSklDLager]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDLager_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDLager_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDLager_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblSklDLager table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDLager_Insert
(

	@ID int    OUTPUT,

	@SifraArtikla int   ,

	@NazivArtikla nvarchar (250)  ,

	@Batch nvarchar (250)  ,

	@NettoMasa money   ,

	@Kolicina money   ,

	@Cijena money   ,

	@Valuta nvarchar (50)  ,

	@Porijeklo nvarchar (250)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblSklDLager]
					(
					[SifraArtikla]
					,[NazivArtikla]
					,[Batch]
					,[NettoMasa]
					,[Kolicina]
					,[Cijena]
					,[Valuta]
					,[Porijeklo]
					)
				VALUES
					(
					@SifraArtikla
					,@NazivArtikla
					,@Batch
					,@NettoMasa
					,@Kolicina
					,@Cijena
					,@Valuta
					,@Porijeklo
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDLager_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDLager_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDLager_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblSklDLager table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDLager_Update
(

	@ID int   ,

	@SifraArtikla int   ,

	@NazivArtikla nvarchar (250)  ,

	@Batch nvarchar (250)  ,

	@NettoMasa money   ,

	@Kolicina money   ,

	@Cijena money   ,

	@Valuta nvarchar (50)  ,

	@Porijeklo nvarchar (250)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblSklDLager]
				SET
					[SifraArtikla] = @SifraArtikla
					,[NazivArtikla] = @NazivArtikla
					,[Batch] = @Batch
					,[NettoMasa] = @NettoMasa
					,[Kolicina] = @Kolicina
					,[Cijena] = @Cijena
					,[Valuta] = @Valuta
					,[Porijeklo] = @Porijeklo
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDLager_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDLager_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDLager_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblSklDLager table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDLager_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblSklDLager] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDLager_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDLager_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDLager_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblSklDLager table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDLager_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[SifraArtikla],
					[NazivArtikla],
					[Batch],
					[NettoMasa],
					[Kolicina],
					[Cijena],
					[Valuta],
					[Porijeklo]
				FROM
					[dbo].[tblSklDLager]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDLager_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDLager_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDLager_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblSklDLager table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDLager_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@SifraArtikla int   = null ,

	@NazivArtikla nvarchar (250)  = null ,

	@Batch nvarchar (250)  = null ,

	@NettoMasa money   = null ,

	@Kolicina money   = null ,

	@Cijena money   = null ,

	@Valuta nvarchar (50)  = null ,

	@Porijeklo nvarchar (250)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [SifraArtikla]
	, [NazivArtikla]
	, [Batch]
	, [NettoMasa]
	, [Kolicina]
	, [Cijena]
	, [Valuta]
	, [Porijeklo]
    FROM
	[dbo].[tblSklDLager]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([SifraArtikla] = @SifraArtikla OR @SifraArtikla is null)
	AND ([NazivArtikla] = @NazivArtikla OR @NazivArtikla is null)
	AND ([Batch] = @Batch OR @Batch is null)
	AND ([NettoMasa] = @NettoMasa OR @NettoMasa is null)
	AND ([Kolicina] = @Kolicina OR @Kolicina is null)
	AND ([Cijena] = @Cijena OR @Cijena is null)
	AND ([Valuta] = @Valuta OR @Valuta is null)
	AND ([Porijeklo] = @Porijeklo OR @Porijeklo is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [SifraArtikla]
	, [NazivArtikla]
	, [Batch]
	, [NettoMasa]
	, [Kolicina]
	, [Cijena]
	, [Valuta]
	, [Porijeklo]
    FROM
	[dbo].[tblSklDLager]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([SifraArtikla] = @SifraArtikla AND @SifraArtikla is not null)
	OR ([NazivArtikla] = @NazivArtikla AND @NazivArtikla is not null)
	OR ([Batch] = @Batch AND @Batch is not null)
	OR ([NettoMasa] = @NettoMasa AND @NettoMasa is not null)
	OR ([Kolicina] = @Kolicina AND @Kolicina is not null)
	OR ([Cijena] = @Cijena AND @Cijena is not null)
	OR ([Valuta] = @Valuta AND @Valuta is not null)
	OR ([Porijeklo] = @Porijeklo AND @Porijeklo is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnikTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnikTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnikTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblSifarnikTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnikTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[DatumOd],
					[DatumDo],
					[Grupa]
				FROM
					[pla].[tblSifarnikTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnikTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnikTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnikTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblSifarnikTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnikTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [Grupa]'
				SET @SQL = @SQL + ' FROM [pla].[tblSifarnikTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [Grupa]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblSifarnikTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnikTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnikTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnikTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblSifarnikTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnikTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (200)  ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@Grupa nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblSifarnikTip]
					(
					[Naziv]
					,[DatumOd]
					,[DatumDo]
					,[Grupa]
					)
				VALUES
					(
					@Naziv
					,@DatumOd
					,@DatumDo
					,@Grupa
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnikTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnikTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnikTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblSifarnikTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnikTip_Update
(

	@ID int   ,

	@Naziv nvarchar (200)  ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@Grupa nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblSifarnikTip]
				SET
					[Naziv] = @Naziv
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[Grupa] = @Grupa
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnikTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnikTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnikTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblSifarnikTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnikTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblSifarnikTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnikTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnikTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnikTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblSifarnikTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnikTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[DatumOd],
					[DatumDo],
					[Grupa]
				FROM
					[pla].[tblSifarnikTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnikTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnikTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnikTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblSifarnikTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnikTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (200)  = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@Grupa nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [DatumOd]
	, [DatumDo]
	, [Grupa]
    FROM
	[pla].[tblSifarnikTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([Grupa] = @Grupa OR @Grupa is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [DatumOd]
	, [DatumDo]
	, [Grupa]
    FROM
	[pla].[tblSifarnikTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([Grupa] = @Grupa AND @Grupa is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtjevGlava_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtjevGlava_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtjevGlava_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblSklDZahtjevGlava table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtjevGlava_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Datum],
					[Oznaka],
					[Server],
					[IDUser],
					[IDStatus]
				FROM
					[dbo].[tblSklDZahtjevGlava]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtjevGlava_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtjevGlava_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtjevGlava_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblSklDZahtjevGlava table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtjevGlava_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [Server]'
				SET @SQL = @SQL + ', [IDUser]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ' FROM [dbo].[tblSklDZahtjevGlava]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [Server],'
				SET @SQL = @SQL + ' [IDUser],'
				SET @SQL = @SQL + ' [IDStatus]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblSklDZahtjevGlava]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtjevGlava_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtjevGlava_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtjevGlava_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblSklDZahtjevGlava table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtjevGlava_Insert
(

	@ID int    OUTPUT,

	@Datum datetime   ,

	@Oznaka nvarchar (250)  ,

	@Server nvarchar (50)  ,

	@IDUser int   ,

	@IDStatus int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblSklDZahtjevGlava]
					(
					[Datum]
					,[Oznaka]
					,[Server]
					,[IDUser]
					,[IDStatus]
					)
				VALUES
					(
					@Datum
					,@Oznaka
					,@Server
					,@IDUser
					,@IDStatus
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtjevGlava_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtjevGlava_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtjevGlava_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblSklDZahtjevGlava table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtjevGlava_Update
(

	@ID int   ,

	@Datum datetime   ,

	@Oznaka nvarchar (250)  ,

	@Server nvarchar (50)  ,

	@IDUser int   ,

	@IDStatus int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblSklDZahtjevGlava]
				SET
					[Datum] = @Datum
					,[Oznaka] = @Oznaka
					,[Server] = @Server
					,[IDUser] = @IDUser
					,[IDStatus] = @IDStatus
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtjevGlava_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtjevGlava_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtjevGlava_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblSklDZahtjevGlava table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtjevGlava_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblSklDZahtjevGlava] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtjevGlava_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtjevGlava_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtjevGlava_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblSklDZahtjevGlava table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtjevGlava_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Datum],
					[Oznaka],
					[Server],
					[IDUser],
					[IDStatus]
				FROM
					[dbo].[tblSklDZahtjevGlava]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblSklDZahtjevGlava_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSklDZahtjevGlava_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSklDZahtjevGlava_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblSklDZahtjevGlava table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSklDZahtjevGlava_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Datum datetime   = null ,

	@Oznaka nvarchar (250)  = null ,

	@Server nvarchar (50)  = null ,

	@IDUser int   = null ,

	@IDStatus int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Datum]
	, [Oznaka]
	, [Server]
	, [IDUser]
	, [IDStatus]
    FROM
	[dbo].[tblSklDZahtjevGlava]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Datum] = @Datum OR @Datum is null)
	AND ([Oznaka] = @Oznaka OR @Oznaka is null)
	AND ([Server] = @Server OR @Server is null)
	AND ([IDUser] = @IDUser OR @IDUser is null)
	AND ([IDStatus] = @IDStatus OR @IDStatus is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Datum]
	, [Oznaka]
	, [Server]
	, [IDUser]
	, [IDStatus]
    FROM
	[dbo].[tblSklDZahtjevGlava]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Datum] = @Datum AND @Datum is not null)
	OR ([Oznaka] = @Oznaka AND @Oznaka is not null)
	OR ([Server] = @Server AND @Server is not null)
	OR ([IDUser] = @IDUser AND @IDUser is not null)
	OR ([IDStatus] = @IDStatus AND @IDStatus is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnik_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnik_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnik_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblSifarnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnik_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDSifarnikTip],
					[Naziv],
					[Sifra],
					[VrijednostInt],
					[VrijednostReal],
					[VrijednostMoney],
					[VrijednostDatum],
					[VrijednostTekst]
				FROM
					[pla].[tblSifarnik]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnik_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnik_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnik_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblSifarnik table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnik_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDSifarnikTip]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Sifra]'
				SET @SQL = @SQL + ', [VrijednostInt]'
				SET @SQL = @SQL + ', [VrijednostReal]'
				SET @SQL = @SQL + ', [VrijednostMoney]'
				SET @SQL = @SQL + ', [VrijednostDatum]'
				SET @SQL = @SQL + ', [VrijednostTekst]'
				SET @SQL = @SQL + ' FROM [pla].[tblSifarnik]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDSifarnikTip],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Sifra],'
				SET @SQL = @SQL + ' [VrijednostInt],'
				SET @SQL = @SQL + ' [VrijednostReal],'
				SET @SQL = @SQL + ' [VrijednostMoney],'
				SET @SQL = @SQL + ' [VrijednostDatum],'
				SET @SQL = @SQL + ' [VrijednostTekst]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblSifarnik]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnik_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnik_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnik_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblSifarnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnik_Insert
(

	@ID int    OUTPUT,

	@IDSifarnikTip int   ,

	@Naziv nvarchar (300)  ,

	@Sifra nvarchar (10)  ,

	@VrijednostInt int   ,

	@VrijednostReal real   ,

	@VrijednostMoney money   ,

	@VrijednostDatum datetime   ,

	@VrijednostTekst nvarchar (250)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblSifarnik]
					(
					[IDSifarnikTip]
					,[Naziv]
					,[Sifra]
					,[VrijednostInt]
					,[VrijednostReal]
					,[VrijednostMoney]
					,[VrijednostDatum]
					,[VrijednostTekst]
					)
				VALUES
					(
					@IDSifarnikTip
					,@Naziv
					,@Sifra
					,@VrijednostInt
					,@VrijednostReal
					,@VrijednostMoney
					,@VrijednostDatum
					,@VrijednostTekst
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnik_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnik_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnik_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblSifarnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnik_Update
(

	@ID int   ,

	@IDSifarnikTip int   ,

	@Naziv nvarchar (300)  ,

	@Sifra nvarchar (10)  ,

	@VrijednostInt int   ,

	@VrijednostReal real   ,

	@VrijednostMoney money   ,

	@VrijednostDatum datetime   ,

	@VrijednostTekst nvarchar (250)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblSifarnik]
				SET
					[IDSifarnikTip] = @IDSifarnikTip
					,[Naziv] = @Naziv
					,[Sifra] = @Sifra
					,[VrijednostInt] = @VrijednostInt
					,[VrijednostReal] = @VrijednostReal
					,[VrijednostMoney] = @VrijednostMoney
					,[VrijednostDatum] = @VrijednostDatum
					,[VrijednostTekst] = @VrijednostTekst
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnik_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnik_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnik_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblSifarnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnik_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblSifarnik] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnik_GetByIDSifarnikTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnik_GetByIDSifarnikTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnik_GetByIDSifarnikTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblSifarnik table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnik_GetByIDSifarnikTip
(

	@IDSifarnikTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDSifarnikTip],
					[Naziv],
					[Sifra],
					[VrijednostInt],
					[VrijednostReal],
					[VrijednostMoney],
					[VrijednostDatum],
					[VrijednostTekst]
				FROM
					[pla].[tblSifarnik]
				WHERE
					[IDSifarnikTip] = @IDSifarnikTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnik_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnik_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnik_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblSifarnik table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnik_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDSifarnikTip],
					[Naziv],
					[Sifra],
					[VrijednostInt],
					[VrijednostReal],
					[VrijednostMoney],
					[VrijednostDatum],
					[VrijednostTekst]
				FROM
					[pla].[tblSifarnik]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblSifarnik_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblSifarnik_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblSifarnik_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblSifarnik table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblSifarnik_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDSifarnikTip int   = null ,

	@Naziv nvarchar (300)  = null ,

	@Sifra nvarchar (10)  = null ,

	@VrijednostInt int   = null ,

	@VrijednostReal real   = null ,

	@VrijednostMoney money   = null ,

	@VrijednostDatum datetime   = null ,

	@VrijednostTekst nvarchar (250)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDSifarnikTip]
	, [Naziv]
	, [Sifra]
	, [VrijednostInt]
	, [VrijednostReal]
	, [VrijednostMoney]
	, [VrijednostDatum]
	, [VrijednostTekst]
    FROM
	[pla].[tblSifarnik]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDSifarnikTip] = @IDSifarnikTip OR @IDSifarnikTip is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Sifra] = @Sifra OR @Sifra is null)
	AND ([VrijednostInt] = @VrijednostInt OR @VrijednostInt is null)
	AND ([VrijednostReal] = @VrijednostReal OR @VrijednostReal is null)
	AND ([VrijednostMoney] = @VrijednostMoney OR @VrijednostMoney is null)
	AND ([VrijednostDatum] = @VrijednostDatum OR @VrijednostDatum is null)
	AND ([VrijednostTekst] = @VrijednostTekst OR @VrijednostTekst is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDSifarnikTip]
	, [Naziv]
	, [Sifra]
	, [VrijednostInt]
	, [VrijednostReal]
	, [VrijednostMoney]
	, [VrijednostDatum]
	, [VrijednostTekst]
    FROM
	[pla].[tblSifarnik]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDSifarnikTip] = @IDSifarnikTip AND @IDSifarnikTip is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Sifra] = @Sifra AND @Sifra is not null)
	OR ([VrijednostInt] = @VrijednostInt AND @VrijednostInt is not null)
	OR ([VrijednostReal] = @VrijednostReal AND @VrijednostReal is not null)
	OR ([VrijednostMoney] = @VrijednostMoney AND @VrijednostMoney is not null)
	OR ([VrijednostDatum] = @VrijednostDatum AND @VrijednostDatum is not null)
	OR ([VrijednostTekst] = @VrijednostTekst AND @VrijednostTekst is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblTecajValute_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblTecajValute_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblTecajValute_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblTecajValute table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblTecajValute_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDValuta],
					[Srednji],
					[Kupovni],
					[Prodajni],
					[DatumObjave],
					[IDBanka],
					[DatumPrimjene]
				FROM
					[dbo].[tblTecajValute]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblTecajValute_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblTecajValute_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblTecajValute_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblTecajValute table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblTecajValute_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDValuta]'
				SET @SQL = @SQL + ', [Srednji]'
				SET @SQL = @SQL + ', [Kupovni]'
				SET @SQL = @SQL + ', [Prodajni]'
				SET @SQL = @SQL + ', [DatumObjave]'
				SET @SQL = @SQL + ', [IDBanka]'
				SET @SQL = @SQL + ', [DatumPrimjene]'
				SET @SQL = @SQL + ' FROM [dbo].[tblTecajValute]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDValuta],'
				SET @SQL = @SQL + ' [Srednji],'
				SET @SQL = @SQL + ' [Kupovni],'
				SET @SQL = @SQL + ' [Prodajni],'
				SET @SQL = @SQL + ' [DatumObjave],'
				SET @SQL = @SQL + ' [IDBanka],'
				SET @SQL = @SQL + ' [DatumPrimjene]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblTecajValute]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblTecajValute_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblTecajValute_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblTecajValute_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblTecajValute table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblTecajValute_Insert
(

	@ID int    OUTPUT,

	@IDValuta int   ,

	@Srednji real   ,

	@Kupovni real   ,

	@Prodajni real   ,

	@DatumObjave datetime   ,

	@IDBanka int   ,

	@DatumPrimjene datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblTecajValute]
					(
					[IDValuta]
					,[Srednji]
					,[Kupovni]
					,[Prodajni]
					,[DatumObjave]
					,[IDBanka]
					,[DatumPrimjene]
					)
				VALUES
					(
					@IDValuta
					,@Srednji
					,@Kupovni
					,@Prodajni
					,@DatumObjave
					,@IDBanka
					,@DatumPrimjene
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblTecajValute_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblTecajValute_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblTecajValute_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblTecajValute table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblTecajValute_Update
(

	@ID int   ,

	@IDValuta int   ,

	@Srednji real   ,

	@Kupovni real   ,

	@Prodajni real   ,

	@DatumObjave datetime   ,

	@IDBanka int   ,

	@DatumPrimjene datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblTecajValute]
				SET
					[IDValuta] = @IDValuta
					,[Srednji] = @Srednji
					,[Kupovni] = @Kupovni
					,[Prodajni] = @Prodajni
					,[DatumObjave] = @DatumObjave
					,[IDBanka] = @IDBanka
					,[DatumPrimjene] = @DatumPrimjene
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblTecajValute_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblTecajValute_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblTecajValute_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblTecajValute table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblTecajValute_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblTecajValute] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblTecajValute_GetByIDBanka procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblTecajValute_GetByIDBanka') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblTecajValute_GetByIDBanka
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblTecajValute table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblTecajValute_GetByIDBanka
(

	@IDBanka int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDValuta],
					[Srednji],
					[Kupovni],
					[Prodajni],
					[DatumObjave],
					[IDBanka],
					[DatumPrimjene]
				FROM
					[dbo].[tblTecajValute]
				WHERE
					[IDBanka] = @IDBanka
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblTecajValute_GetByIDValuta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblTecajValute_GetByIDValuta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblTecajValute_GetByIDValuta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblTecajValute table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblTecajValute_GetByIDValuta
(

	@IDValuta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDValuta],
					[Srednji],
					[Kupovni],
					[Prodajni],
					[DatumObjave],
					[IDBanka],
					[DatumPrimjene]
				FROM
					[dbo].[tblTecajValute]
				WHERE
					[IDValuta] = @IDValuta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblTecajValute_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblTecajValute_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblTecajValute_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblTecajValute table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblTecajValute_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDValuta],
					[Srednji],
					[Kupovni],
					[Prodajni],
					[DatumObjave],
					[IDBanka],
					[DatumPrimjene]
				FROM
					[dbo].[tblTecajValute]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblTecajValute_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblTecajValute_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblTecajValute_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblTecajValute table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblTecajValute_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDValuta int   = null ,

	@Srednji real   = null ,

	@Kupovni real   = null ,

	@Prodajni real   = null ,

	@DatumObjave datetime   = null ,

	@IDBanka int   = null ,

	@DatumPrimjene datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDValuta]
	, [Srednji]
	, [Kupovni]
	, [Prodajni]
	, [DatumObjave]
	, [IDBanka]
	, [DatumPrimjene]
    FROM
	[dbo].[tblTecajValute]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDValuta] = @IDValuta OR @IDValuta is null)
	AND ([Srednji] = @Srednji OR @Srednji is null)
	AND ([Kupovni] = @Kupovni OR @Kupovni is null)
	AND ([Prodajni] = @Prodajni OR @Prodajni is null)
	AND ([DatumObjave] = @DatumObjave OR @DatumObjave is null)
	AND ([IDBanka] = @IDBanka OR @IDBanka is null)
	AND ([DatumPrimjene] = @DatumPrimjene OR @DatumPrimjene is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDValuta]
	, [Srednji]
	, [Kupovni]
	, [Prodajni]
	, [DatumObjave]
	, [IDBanka]
	, [DatumPrimjene]
    FROM
	[dbo].[tblTecajValute]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDValuta] = @IDValuta AND @IDValuta is not null)
	OR ([Srednji] = @Srednji AND @Srednji is not null)
	OR ([Kupovni] = @Kupovni AND @Kupovni is not null)
	OR ([Prodajni] = @Prodajni AND @Prodajni is not null)
	OR ([DatumObjave] = @DatumObjave AND @DatumObjave is not null)
	OR ([IDBanka] = @IDBanka AND @IDBanka is not null)
	OR ([DatumPrimjene] = @DatumPrimjene AND @DatumPrimjene is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblVrstaRaspodjele_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblVrstaRaspodjele_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblVrstaRaspodjele_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblVrstaRaspodjele table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblVrstaRaspodjele_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblVrstaRaspodjele]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblVrstaRaspodjele_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblVrstaRaspodjele_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblVrstaRaspodjele_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblVrstaRaspodjele table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblVrstaRaspodjele_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [pla].[tblVrstaRaspodjele]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblVrstaRaspodjele]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblVrstaRaspodjele_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblVrstaRaspodjele_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblVrstaRaspodjele_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblVrstaRaspodjele table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblVrstaRaspodjele_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (25)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblVrstaRaspodjele]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblVrstaRaspodjele_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblVrstaRaspodjele_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblVrstaRaspodjele_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblVrstaRaspodjele table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblVrstaRaspodjele_Update
(

	@ID int   ,

	@Naziv nvarchar (25)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblVrstaRaspodjele]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblVrstaRaspodjele_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblVrstaRaspodjele_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblVrstaRaspodjele_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblVrstaRaspodjele table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblVrstaRaspodjele_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblVrstaRaspodjele] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblVrstaRaspodjele_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblVrstaRaspodjele_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblVrstaRaspodjele_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblVrstaRaspodjele table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblVrstaRaspodjele_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblVrstaRaspodjele]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblVrstaRaspodjele_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblVrstaRaspodjele_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblVrstaRaspodjele_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblVrstaRaspodjele table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblVrstaRaspodjele_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (25)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblVrstaRaspodjele]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblVrstaRaspodjele]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVozilo_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVozilo_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVozilo_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblVozilo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVozilo_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[OznakaVozila]
				FROM
					[fin].[tblVozilo]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVozilo_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVozilo_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVozilo_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblVozilo table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVozilo_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [OznakaVozila]'
				SET @SQL = @SQL + ' FROM [fin].[tblVozilo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [OznakaVozila]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblVozilo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVozilo_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVozilo_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVozilo_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblVozilo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVozilo_Insert
(

	@ID int    OUTPUT,

	@OznakaVozila nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblVozilo]
					(
					[OznakaVozila]
					)
				VALUES
					(
					@OznakaVozila
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVozilo_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVozilo_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVozilo_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblVozilo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVozilo_Update
(

	@ID int   ,

	@OznakaVozila nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblVozilo]
				SET
					[OznakaVozila] = @OznakaVozila
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVozilo_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVozilo_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVozilo_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblVozilo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVozilo_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblVozilo] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVozilo_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVozilo_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVozilo_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblVozilo table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVozilo_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[OznakaVozila]
				FROM
					[fin].[tblVozilo]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVozilo_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVozilo_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVozilo_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblVozilo table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVozilo_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@OznakaVozila nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [OznakaVozila]
    FROM
	[fin].[tblVozilo]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([OznakaVozila] = @OznakaVozila OR @OznakaVozila is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [OznakaVozila]
    FROM
	[fin].[tblVozilo]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([OznakaVozila] = @OznakaVozila AND @OznakaVozila is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVirman_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVirman_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVirman_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblVirman table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVirman_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[NalogodavateljaNaziv],
					[NalogodavateljaSjediste],
					[NalogodavateljRacun],
					[BrojZaduzenjaModel],
					[BrojZaduzenjaPoziv],
					[SvrhaDoznake],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[PrimateljRacun],
					[BrojOdobrenjaModel],
					[BrojOdobrenjaPoziv],
					[Iznos],
					[DatumIzvrsenja],
					[Placen],
					[IDKnjizenja],
					[IDKlijent],
					[calculated],
					[DatumDospijeca]
				FROM
					[fin].[tblVirman]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVirman_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVirman_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVirman_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblVirman table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVirman_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [NalogodavateljaNaziv]'
				SET @SQL = @SQL + ', [NalogodavateljaSjediste]'
				SET @SQL = @SQL + ', [NalogodavateljRacun]'
				SET @SQL = @SQL + ', [BrojZaduzenjaModel]'
				SET @SQL = @SQL + ', [BrojZaduzenjaPoziv]'
				SET @SQL = @SQL + ', [SvrhaDoznake]'
				SET @SQL = @SQL + ', [PrimateljNaziv]'
				SET @SQL = @SQL + ', [PrimateljSjediste]'
				SET @SQL = @SQL + ', [PrimateljRacun]'
				SET @SQL = @SQL + ', [BrojOdobrenjaModel]'
				SET @SQL = @SQL + ', [BrojOdobrenjaPoziv]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [DatumIzvrsenja]'
				SET @SQL = @SQL + ', [Placen]'
				SET @SQL = @SQL + ', [IDKnjizenja]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [calculated]'
				SET @SQL = @SQL + ', [DatumDospijeca]'
				SET @SQL = @SQL + ' FROM [fin].[tblVirman]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [NalogodavateljaNaziv],'
				SET @SQL = @SQL + ' [NalogodavateljaSjediste],'
				SET @SQL = @SQL + ' [NalogodavateljRacun],'
				SET @SQL = @SQL + ' [BrojZaduzenjaModel],'
				SET @SQL = @SQL + ' [BrojZaduzenjaPoziv],'
				SET @SQL = @SQL + ' [SvrhaDoznake],'
				SET @SQL = @SQL + ' [PrimateljNaziv],'
				SET @SQL = @SQL + ' [PrimateljSjediste],'
				SET @SQL = @SQL + ' [PrimateljRacun],'
				SET @SQL = @SQL + ' [BrojOdobrenjaModel],'
				SET @SQL = @SQL + ' [BrojOdobrenjaPoziv],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [DatumIzvrsenja],'
				SET @SQL = @SQL + ' [Placen],'
				SET @SQL = @SQL + ' [IDKnjizenja],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [calculated],'
				SET @SQL = @SQL + ' [DatumDospijeca]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblVirman]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVirman_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVirman_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVirman_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblVirman table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVirman_Insert
(

	@ID int    OUTPUT,

	@NalogodavateljaNaziv nvarchar (50)  ,

	@NalogodavateljaSjediste nvarchar (50)  ,

	@NalogodavateljRacun nvarchar (26)  ,

	@BrojZaduzenjaModel nvarchar (2)  ,

	@BrojZaduzenjaPoziv nvarchar (23)  ,

	@SvrhaDoznake nvarchar (50)  ,

	@PrimateljNaziv nvarchar (50)  ,

	@PrimateljSjediste nvarchar (50)  ,

	@PrimateljRacun nvarchar (26)  ,

	@BrojOdobrenjaModel nvarchar (2)  ,

	@BrojOdobrenjaPoziv nvarchar (23)  ,

	@Iznos money   ,

	@DatumIzvrsenja datetime   ,

	@Placen bit   ,

	@IDKnjizenja int   ,

	@IDKlijent int   ,

	@Calculated int    OUTPUT,

	@DatumDospijeca datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblVirman]
					(
					[NalogodavateljaNaziv]
					,[NalogodavateljaSjediste]
					,[NalogodavateljRacun]
					,[BrojZaduzenjaModel]
					,[BrojZaduzenjaPoziv]
					,[SvrhaDoznake]
					,[PrimateljNaziv]
					,[PrimateljSjediste]
					,[PrimateljRacun]
					,[BrojOdobrenjaModel]
					,[BrojOdobrenjaPoziv]
					,[Iznos]
					,[DatumIzvrsenja]
					,[Placen]
					,[IDKnjizenja]
					,[IDKlijent]
					,[DatumDospijeca]
					)
				VALUES
					(
					@NalogodavateljaNaziv
					,@NalogodavateljaSjediste
					,@NalogodavateljRacun
					,@BrojZaduzenjaModel
					,@BrojZaduzenjaPoziv
					,@SvrhaDoznake
					,@PrimateljNaziv
					,@PrimateljSjediste
					,@PrimateljRacun
					,@BrojOdobrenjaModel
					,@BrojOdobrenjaPoziv
					,@Iznos
					,@DatumIzvrsenja
					,@Placen
					,@IDKnjizenja
					,@IDKlijent
					,@DatumDospijeca
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
				-- Select computed columns into output parameters
				SELECT
 @Calculated = [calculated]
				FROM
					[fin].[tblVirman]
				WHERE
[ID] = @ID 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVirman_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVirman_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVirman_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblVirman table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVirman_Update
(

	@ID int   ,

	@NalogodavateljaNaziv nvarchar (50)  ,

	@NalogodavateljaSjediste nvarchar (50)  ,

	@NalogodavateljRacun nvarchar (26)  ,

	@BrojZaduzenjaModel nvarchar (2)  ,

	@BrojZaduzenjaPoziv nvarchar (23)  ,

	@SvrhaDoznake nvarchar (50)  ,

	@PrimateljNaziv nvarchar (50)  ,

	@PrimateljSjediste nvarchar (50)  ,

	@PrimateljRacun nvarchar (26)  ,

	@BrojOdobrenjaModel nvarchar (2)  ,

	@BrojOdobrenjaPoziv nvarchar (23)  ,

	@Iznos money   ,

	@DatumIzvrsenja datetime   ,

	@Placen bit   ,

	@IDKnjizenja int   ,

	@IDKlijent int   ,

	@Calculated int    OUTPUT,

	@DatumDospijeca datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblVirman]
				SET
					[NalogodavateljaNaziv] = @NalogodavateljaNaziv
					,[NalogodavateljaSjediste] = @NalogodavateljaSjediste
					,[NalogodavateljRacun] = @NalogodavateljRacun
					,[BrojZaduzenjaModel] = @BrojZaduzenjaModel
					,[BrojZaduzenjaPoziv] = @BrojZaduzenjaPoziv
					,[SvrhaDoznake] = @SvrhaDoznake
					,[PrimateljNaziv] = @PrimateljNaziv
					,[PrimateljSjediste] = @PrimateljSjediste
					,[PrimateljRacun] = @PrimateljRacun
					,[BrojOdobrenjaModel] = @BrojOdobrenjaModel
					,[BrojOdobrenjaPoziv] = @BrojOdobrenjaPoziv
					,[Iznos] = @Iznos
					,[DatumIzvrsenja] = @DatumIzvrsenja
					,[Placen] = @Placen
					,[IDKnjizenja] = @IDKnjizenja
					,[IDKlijent] = @IDKlijent
					,[DatumDospijeca] = @DatumDospijeca
				WHERE
[ID] = @ID 
				
				
				-- Select computed columns into output parameters
				SELECT
 @Calculated = [calculated]
				FROM
					[fin].[tblVirman]
				WHERE
[ID] = @ID 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVirman_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVirman_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVirman_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblVirman table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVirman_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblVirman] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVirman_GetByIDKlijent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVirman_GetByIDKlijent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVirman_GetByIDKlijent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblVirman table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVirman_GetByIDKlijent
(

	@IDKlijent int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[NalogodavateljaNaziv],
					[NalogodavateljaSjediste],
					[NalogodavateljRacun],
					[BrojZaduzenjaModel],
					[BrojZaduzenjaPoziv],
					[SvrhaDoznake],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[PrimateljRacun],
					[BrojOdobrenjaModel],
					[BrojOdobrenjaPoziv],
					[Iznos],
					[DatumIzvrsenja],
					[Placen],
					[IDKnjizenja],
					[IDKlijent],
					[calculated],
					[DatumDospijeca]
				FROM
					[fin].[tblVirman]
				WHERE
					[IDKlijent] = @IDKlijent
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVirman_GetByIDKnjizenja procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVirman_GetByIDKnjizenja') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVirman_GetByIDKnjizenja
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblVirman table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVirman_GetByIDKnjizenja
(

	@IDKnjizenja int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[NalogodavateljaNaziv],
					[NalogodavateljaSjediste],
					[NalogodavateljRacun],
					[BrojZaduzenjaModel],
					[BrojZaduzenjaPoziv],
					[SvrhaDoznake],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[PrimateljRacun],
					[BrojOdobrenjaModel],
					[BrojOdobrenjaPoziv],
					[Iznos],
					[DatumIzvrsenja],
					[Placen],
					[IDKnjizenja],
					[IDKlijent],
					[calculated],
					[DatumDospijeca]
				FROM
					[fin].[tblVirman]
				WHERE
					[IDKnjizenja] = @IDKnjizenja
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVirman_GetByIDKnjizenjaCalculated procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVirman_GetByIDKnjizenjaCalculated') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVirman_GetByIDKnjizenjaCalculated
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblVirman table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVirman_GetByIDKnjizenjaCalculated
(

	@IDKnjizenja int   ,

	@Calculated int   
)
AS


				SELECT
					[ID],
					[NalogodavateljaNaziv],
					[NalogodavateljaSjediste],
					[NalogodavateljRacun],
					[BrojZaduzenjaModel],
					[BrojZaduzenjaPoziv],
					[SvrhaDoznake],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[PrimateljRacun],
					[BrojOdobrenjaModel],
					[BrojOdobrenjaPoziv],
					[Iznos],
					[DatumIzvrsenja],
					[Placen],
					[IDKnjizenja],
					[IDKlijent],
					[calculated],
					[DatumDospijeca]
				FROM
					[fin].[tblVirman]
				WHERE
					[IDKnjizenja] = @IDKnjizenja
					AND [calculated] = @Calculated
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVirman_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVirman_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVirman_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblVirman table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVirman_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[NalogodavateljaNaziv],
					[NalogodavateljaSjediste],
					[NalogodavateljRacun],
					[BrojZaduzenjaModel],
					[BrojZaduzenjaPoziv],
					[SvrhaDoznake],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[PrimateljRacun],
					[BrojOdobrenjaModel],
					[BrojOdobrenjaPoziv],
					[Iznos],
					[DatumIzvrsenja],
					[Placen],
					[IDKnjizenja],
					[IDKlijent],
					[calculated],
					[DatumDospijeca]
				FROM
					[fin].[tblVirman]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblVirman_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblVirman_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblVirman_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblVirman table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblVirman_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@NalogodavateljaNaziv nvarchar (50)  = null ,

	@NalogodavateljaSjediste nvarchar (50)  = null ,

	@NalogodavateljRacun nvarchar (26)  = null ,

	@BrojZaduzenjaModel nvarchar (2)  = null ,

	@BrojZaduzenjaPoziv nvarchar (23)  = null ,

	@SvrhaDoznake nvarchar (50)  = null ,

	@PrimateljNaziv nvarchar (50)  = null ,

	@PrimateljSjediste nvarchar (50)  = null ,

	@PrimateljRacun nvarchar (26)  = null ,

	@BrojOdobrenjaModel nvarchar (2)  = null ,

	@BrojOdobrenjaPoziv nvarchar (23)  = null ,

	@Iznos money   = null ,

	@DatumIzvrsenja datetime   = null ,

	@Placen bit   = null ,

	@IDKnjizenja int   = null ,

	@IDKlijent int   = null ,

	@Calculated int   = null ,

	@DatumDospijeca datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [NalogodavateljaNaziv]
	, [NalogodavateljaSjediste]
	, [NalogodavateljRacun]
	, [BrojZaduzenjaModel]
	, [BrojZaduzenjaPoziv]
	, [SvrhaDoznake]
	, [PrimateljNaziv]
	, [PrimateljSjediste]
	, [PrimateljRacun]
	, [BrojOdobrenjaModel]
	, [BrojOdobrenjaPoziv]
	, [Iznos]
	, [DatumIzvrsenja]
	, [Placen]
	, [IDKnjizenja]
	, [IDKlijent]
	, [calculated]
	, [DatumDospijeca]
    FROM
	[fin].[tblVirman]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([NalogodavateljaNaziv] = @NalogodavateljaNaziv OR @NalogodavateljaNaziv is null)
	AND ([NalogodavateljaSjediste] = @NalogodavateljaSjediste OR @NalogodavateljaSjediste is null)
	AND ([NalogodavateljRacun] = @NalogodavateljRacun OR @NalogodavateljRacun is null)
	AND ([BrojZaduzenjaModel] = @BrojZaduzenjaModel OR @BrojZaduzenjaModel is null)
	AND ([BrojZaduzenjaPoziv] = @BrojZaduzenjaPoziv OR @BrojZaduzenjaPoziv is null)
	AND ([SvrhaDoznake] = @SvrhaDoznake OR @SvrhaDoznake is null)
	AND ([PrimateljNaziv] = @PrimateljNaziv OR @PrimateljNaziv is null)
	AND ([PrimateljSjediste] = @PrimateljSjediste OR @PrimateljSjediste is null)
	AND ([PrimateljRacun] = @PrimateljRacun OR @PrimateljRacun is null)
	AND ([BrojOdobrenjaModel] = @BrojOdobrenjaModel OR @BrojOdobrenjaModel is null)
	AND ([BrojOdobrenjaPoziv] = @BrojOdobrenjaPoziv OR @BrojOdobrenjaPoziv is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
	AND ([DatumIzvrsenja] = @DatumIzvrsenja OR @DatumIzvrsenja is null)
	AND ([Placen] = @Placen OR @Placen is null)
	AND ([IDKnjizenja] = @IDKnjizenja OR @IDKnjizenja is null)
	AND ([IDKlijent] = @IDKlijent OR @IDKlijent is null)
	AND ([calculated] = @Calculated OR @Calculated is null)
	AND ([DatumDospijeca] = @DatumDospijeca OR @DatumDospijeca is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [NalogodavateljaNaziv]
	, [NalogodavateljaSjediste]
	, [NalogodavateljRacun]
	, [BrojZaduzenjaModel]
	, [BrojZaduzenjaPoziv]
	, [SvrhaDoznake]
	, [PrimateljNaziv]
	, [PrimateljSjediste]
	, [PrimateljRacun]
	, [BrojOdobrenjaModel]
	, [BrojOdobrenjaPoziv]
	, [Iznos]
	, [DatumIzvrsenja]
	, [Placen]
	, [IDKnjizenja]
	, [IDKlijent]
	, [calculated]
	, [DatumDospijeca]
    FROM
	[fin].[tblVirman]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([NalogodavateljaNaziv] = @NalogodavateljaNaziv AND @NalogodavateljaNaziv is not null)
	OR ([NalogodavateljaSjediste] = @NalogodavateljaSjediste AND @NalogodavateljaSjediste is not null)
	OR ([NalogodavateljRacun] = @NalogodavateljRacun AND @NalogodavateljRacun is not null)
	OR ([BrojZaduzenjaModel] = @BrojZaduzenjaModel AND @BrojZaduzenjaModel is not null)
	OR ([BrojZaduzenjaPoziv] = @BrojZaduzenjaPoziv AND @BrojZaduzenjaPoziv is not null)
	OR ([SvrhaDoznake] = @SvrhaDoznake AND @SvrhaDoznake is not null)
	OR ([PrimateljNaziv] = @PrimateljNaziv AND @PrimateljNaziv is not null)
	OR ([PrimateljSjediste] = @PrimateljSjediste AND @PrimateljSjediste is not null)
	OR ([PrimateljRacun] = @PrimateljRacun AND @PrimateljRacun is not null)
	OR ([BrojOdobrenjaModel] = @BrojOdobrenjaModel AND @BrojOdobrenjaModel is not null)
	OR ([BrojOdobrenjaPoziv] = @BrojOdobrenjaPoziv AND @BrojOdobrenjaPoziv is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	OR ([DatumIzvrsenja] = @DatumIzvrsenja AND @DatumIzvrsenja is not null)
	OR ([Placen] = @Placen AND @Placen is not null)
	OR ([IDKnjizenja] = @IDKnjizenja AND @IDKnjizenja is not null)
	OR ([IDKlijent] = @IDKlijent AND @IDKlijent is not null)
	OR ([calculated] = @Calculated AND @Calculated is not null)
	OR ([DatumDospijeca] = @DatumDospijeca AND @DatumDospijeca is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblVeza_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblVeza_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblVeza_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblVeza table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblVeza_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDParent],
					[IDChild],
					[Hierarchy],
					[Lvl],
					[HierarchyComputed]
				FROM
					[dbo].[tblVeza]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblVeza_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblVeza_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblVeza_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblVeza table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblVeza_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDParent]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDParent]'
				SET @SQL = @SQL + ', [IDChild]'
				SET @SQL = @SQL + ', [Hierarchy]'
				SET @SQL = @SQL + ', [Lvl]'
				SET @SQL = @SQL + ', [HierarchyComputed]'
				SET @SQL = @SQL + ' FROM [dbo].[tblVeza]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDParent],'
				SET @SQL = @SQL + ' [IDChild],'
				SET @SQL = @SQL + ' [Hierarchy],'
				SET @SQL = @SQL + ' [Lvl],'
				SET @SQL = @SQL + ' [HierarchyComputed]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblVeza]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblVeza_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblVeza_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblVeza_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblVeza table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblVeza_Insert
(

	@IDParent int   ,

	@IDChild int   ,

	@Hierarchy nvarchar (200)  ,

	@Lvl int    OUTPUT,

	@HierarchyComputed nvarchar (200)   OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblVeza]
					(
					[IDParent]
					,[IDChild]
					,[Hierarchy]
					)
				VALUES
					(
					@IDParent
					,@IDChild
					,@Hierarchy
					)
				
									
				-- Select computed columns into output parameters
				SELECT
 @Lvl = [Lvl]
, @HierarchyComputed = [HierarchyComputed]
				FROM
					[dbo].[tblVeza]
				WHERE
[IDParent] = @IDParent 
AND [IDChild] = @IDChild 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblVeza_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblVeza_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblVeza_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblVeza table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblVeza_Update
(

	@IDParent int   ,

	@OriginalIDParent int   ,

	@IDChild int   ,

	@OriginalIDChild int   ,

	@Hierarchy nvarchar (200)  ,

	@Lvl int    OUTPUT,

	@HierarchyComputed nvarchar (200)   OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblVeza]
				SET
					[IDParent] = @IDParent
					,[IDChild] = @IDChild
					,[Hierarchy] = @Hierarchy
				WHERE
[IDParent] = @OriginalIDParent 
AND [IDChild] = @OriginalIDChild 
				
				
				-- Select computed columns into output parameters
				SELECT
 @Lvl = [Lvl]
, @HierarchyComputed = [HierarchyComputed]
				FROM
					[dbo].[tblVeza]
				WHERE
[IDParent] = @IDParent 
AND [IDChild] = @IDChild 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblVeza_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblVeza_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblVeza_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblVeza table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblVeza_Delete
(

	@IDParent int   ,

	@IDChild int   
)
AS


				DELETE FROM [dbo].[tblVeza] WITH (ROWLOCK) 
				WHERE
					[IDParent] = @IDParent
					AND [IDChild] = @IDChild
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblVeza_GetByIDChild procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblVeza_GetByIDChild') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblVeza_GetByIDChild
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblVeza table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblVeza_GetByIDChild
(

	@IDChild int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDParent],
					[IDChild],
					[Hierarchy],
					[Lvl],
					[HierarchyComputed]
				FROM
					[dbo].[tblVeza]
				WHERE
					[IDChild] = @IDChild
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblVeza_GetByIDParent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblVeza_GetByIDParent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblVeza_GetByIDParent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblVeza table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblVeza_GetByIDParent
(

	@IDParent int   
)
AS


				SELECT
					[IDParent],
					[IDChild],
					[Hierarchy],
					[Lvl],
					[HierarchyComputed]
				FROM
					[dbo].[tblVeza]
				WHERE
					[IDParent] = @IDParent
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblVeza_GetByIDParentIDChild procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblVeza_GetByIDParentIDChild') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblVeza_GetByIDParentIDChild
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblVeza table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblVeza_GetByIDParentIDChild
(

	@IDParent int   ,

	@IDChild int   
)
AS


				SELECT
					[IDParent],
					[IDChild],
					[Hierarchy],
					[Lvl],
					[HierarchyComputed]
				FROM
					[dbo].[tblVeza]
				WHERE
					[IDParent] = @IDParent
					AND [IDChild] = @IDChild
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblVeza_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblVeza_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblVeza_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblVeza table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblVeza_Find
(

	@SearchUsingOR bit   = null ,

	@IDParent int   = null ,

	@IDChild int   = null ,

	@Hierarchy nvarchar (200)  = null ,

	@Lvl int   = null ,

	@HierarchyComputed nvarchar (200)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [IDParent]
	, [IDChild]
	, [Hierarchy]
	, [Lvl]
	, [HierarchyComputed]
    FROM
	[dbo].[tblVeza]
    WHERE 
	 ([IDParent] = @IDParent OR @IDParent is null)
	AND ([IDChild] = @IDChild OR @IDChild is null)
	AND ([Hierarchy] = @Hierarchy OR @Hierarchy is null)
	AND ([Lvl] = @Lvl OR @Lvl is null)
	AND ([HierarchyComputed] = @HierarchyComputed OR @HierarchyComputed is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [IDParent]
	, [IDChild]
	, [Hierarchy]
	, [Lvl]
	, [HierarchyComputed]
    FROM
	[dbo].[tblVeza]
    WHERE 
	 ([IDParent] = @IDParent AND @IDParent is not null)
	OR ([IDChild] = @IDChild AND @IDChild is not null)
	OR ([Hierarchy] = @Hierarchy AND @Hierarchy is not null)
	OR ([Lvl] = @Lvl AND @Lvl is not null)
	OR ([HierarchyComputed] = @HierarchyComputed AND @HierarchyComputed is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipIspisa_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipIspisa_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipIspisa_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblTipIspisa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipIspisa_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[fin].[tblTipIspisa]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipIspisa_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipIspisa_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipIspisa_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblTipIspisa table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipIspisa_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [fin].[tblTipIspisa]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblTipIspisa]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipIspisa_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipIspisa_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipIspisa_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblTipIspisa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipIspisa_Insert
(

	@ID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblTipIspisa]
					(
					[ID]
					,[Naziv]
					)
				VALUES
					(
					@ID
					,@Naziv
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipIspisa_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipIspisa_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipIspisa_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblTipIspisa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipIspisa_Update
(

	@ID int   ,

	@OriginalID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblTipIspisa]
				SET
					[ID] = @ID
					,[Naziv] = @Naziv
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipIspisa_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipIspisa_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipIspisa_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblTipIspisa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipIspisa_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblTipIspisa] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipIspisa_GetByNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipIspisa_GetByNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipIspisa_GetByNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblTipIspisa table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipIspisa_GetByNaziv
(

	@Naziv nvarchar (50)  
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[fin].[tblTipIspisa]
				WHERE
					[Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipIspisa_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipIspisa_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipIspisa_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblTipIspisa table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipIspisa_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[fin].[tblTipIspisa]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblTipIspisa_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblTipIspisa_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblTipIspisa_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblTipIspisa table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblTipIspisa_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[fin].[tblTipIspisa]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[fin].[tblTipIspisa]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjeNazivKolona_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjeNazivKolona_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblShemaKnjizenjeNazivKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Kolona],
					[Opis]
				FROM
					[dbo].[tblShemaKnjizenjeNazivKolona]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjeNazivKolona_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjeNazivKolona_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblShemaKnjizenjeNazivKolona table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Kolona]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ' FROM [dbo].[tblShemaKnjizenjeNazivKolona]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Kolona],'
				SET @SQL = @SQL + ' [Opis]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblShemaKnjizenjeNazivKolona]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjeNazivKolona_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjeNazivKolona_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblShemaKnjizenjeNazivKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_Insert
(

	@ID int   ,

	@Kolona nvarchar (15)  ,

	@Opis nvarchar (300)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblShemaKnjizenjeNazivKolona]
					(
					[ID]
					,[Kolona]
					,[Opis]
					)
				VALUES
					(
					@ID
					,@Kolona
					,@Opis
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjeNazivKolona_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjeNazivKolona_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblShemaKnjizenjeNazivKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_Update
(

	@ID int   ,

	@OriginalID int   ,

	@Kolona nvarchar (15)  ,

	@Opis nvarchar (300)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblShemaKnjizenjeNazivKolona]
				SET
					[ID] = @ID
					,[Kolona] = @Kolona
					,[Opis] = @Opis
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjeNazivKolona_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjeNazivKolona_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblShemaKnjizenjeNazivKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblShemaKnjizenjeNazivKolona] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjeNazivKolona_GetByKolona procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjeNazivKolona_GetByKolona') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_GetByKolona
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblShemaKnjizenjeNazivKolona table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_GetByKolona
(

	@Kolona nvarchar (15)  
)
AS


				SELECT
					[ID],
					[Kolona],
					[Opis]
				FROM
					[dbo].[tblShemaKnjizenjeNazivKolona]
				WHERE
					[Kolona] = @Kolona
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjeNazivKolona_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjeNazivKolona_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblShemaKnjizenjeNazivKolona table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Kolona],
					[Opis]
				FROM
					[dbo].[tblShemaKnjizenjeNazivKolona]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjeNazivKolona_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjeNazivKolona_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblShemaKnjizenjeNazivKolona table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjeNazivKolona_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Kolona nvarchar (15)  = null ,

	@Opis nvarchar (300)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Kolona]
	, [Opis]
    FROM
	[dbo].[tblShemaKnjizenjeNazivKolona]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Kolona] = @Kolona OR @Kolona is null)
	AND ([Opis] = @Opis OR @Opis is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Kolona]
	, [Opis]
    FROM
	[dbo].[tblShemaKnjizenjeNazivKolona]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Kolona] = @Kolona AND @Kolona is not null)
	OR ([Opis] = @Opis AND @Opis is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjaRobno_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjaRobno_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjaRobno_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblShemaKnjizenjaRobno table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjaRobno_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[IDKolonaZaPrebacivanje],
					[KontoZaPrebacivanje],
					[IDVrstaFinDokumenta],
					[DugIliPot],
					[RedBr],
					[SklRobeSklPrema],
					[Maloprodaja]
				FROM
					[dbo].[tblShemaKnjizenjaRobno]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjaRobno_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjaRobno_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjaRobno_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblShemaKnjizenjaRobno table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjaRobno_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDDokumentTip]'
				SET @SQL = @SQL + ', [IDKolonaZaPrebacivanje]'
				SET @SQL = @SQL + ', [KontoZaPrebacivanje]'
				SET @SQL = @SQL + ', [IDVrstaFinDokumenta]'
				SET @SQL = @SQL + ', [DugIliPot]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [SklRobeSklPrema]'
				SET @SQL = @SQL + ', [Maloprodaja]'
				SET @SQL = @SQL + ' FROM [dbo].[tblShemaKnjizenjaRobno]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDDokumentTip],'
				SET @SQL = @SQL + ' [IDKolonaZaPrebacivanje],'
				SET @SQL = @SQL + ' [KontoZaPrebacivanje],'
				SET @SQL = @SQL + ' [IDVrstaFinDokumenta],'
				SET @SQL = @SQL + ' [DugIliPot],'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [SklRobeSklPrema],'
				SET @SQL = @SQL + ' [Maloprodaja]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblShemaKnjizenjaRobno]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjaRobno_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjaRobno_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjaRobno_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblShemaKnjizenjaRobno table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjaRobno_Insert
(

	@ID int    OUTPUT,

	@IDDokumentTip int   ,

	@IDKolonaZaPrebacivanje int   ,

	@KontoZaPrebacivanje varchar (9)  ,

	@IDVrstaFinDokumenta int   ,

	@DugIliPot bit   ,

	@RedBr int   ,

	@SklRobeSklPrema bit   ,

	@Maloprodaja bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblShemaKnjizenjaRobno]
					(
					[IDDokumentTip]
					,[IDKolonaZaPrebacivanje]
					,[KontoZaPrebacivanje]
					,[IDVrstaFinDokumenta]
					,[DugIliPot]
					,[RedBr]
					,[SklRobeSklPrema]
					,[Maloprodaja]
					)
				VALUES
					(
					@IDDokumentTip
					,@IDKolonaZaPrebacivanje
					,@KontoZaPrebacivanje
					,@IDVrstaFinDokumenta
					,@DugIliPot
					,@RedBr
					,@SklRobeSklPrema
					,@Maloprodaja
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjaRobno_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjaRobno_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjaRobno_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblShemaKnjizenjaRobno table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjaRobno_Update
(

	@ID int   ,

	@IDDokumentTip int   ,

	@IDKolonaZaPrebacivanje int   ,

	@KontoZaPrebacivanje varchar (9)  ,

	@IDVrstaFinDokumenta int   ,

	@DugIliPot bit   ,

	@RedBr int   ,

	@SklRobeSklPrema bit   ,

	@Maloprodaja bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblShemaKnjizenjaRobno]
				SET
					[IDDokumentTip] = @IDDokumentTip
					,[IDKolonaZaPrebacivanje] = @IDKolonaZaPrebacivanje
					,[KontoZaPrebacivanje] = @KontoZaPrebacivanje
					,[IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
					,[DugIliPot] = @DugIliPot
					,[RedBr] = @RedBr
					,[SklRobeSklPrema] = @SklRobeSklPrema
					,[Maloprodaja] = @Maloprodaja
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjaRobno_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjaRobno_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjaRobno_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblShemaKnjizenjaRobno table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjaRobno_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblShemaKnjizenjaRobno] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjaRobno_GetByIDDokumentTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjaRobno_GetByIDDokumentTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjaRobno_GetByIDDokumentTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblShemaKnjizenjaRobno table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjaRobno_GetByIDDokumentTip
(

	@IDDokumentTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[IDKolonaZaPrebacivanje],
					[KontoZaPrebacivanje],
					[IDVrstaFinDokumenta],
					[DugIliPot],
					[RedBr],
					[SklRobeSklPrema],
					[Maloprodaja]
				FROM
					[dbo].[tblShemaKnjizenjaRobno]
				WHERE
					[IDDokumentTip] = @IDDokumentTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjaRobno_GetByIDKolonaZaPrebacivanje procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjaRobno_GetByIDKolonaZaPrebacivanje') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjaRobno_GetByIDKolonaZaPrebacivanje
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblShemaKnjizenjaRobno table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjaRobno_GetByIDKolonaZaPrebacivanje
(

	@IDKolonaZaPrebacivanje int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[IDKolonaZaPrebacivanje],
					[KontoZaPrebacivanje],
					[IDVrstaFinDokumenta],
					[DugIliPot],
					[RedBr],
					[SklRobeSklPrema],
					[Maloprodaja]
				FROM
					[dbo].[tblShemaKnjizenjaRobno]
				WHERE
					[IDKolonaZaPrebacivanje] = @IDKolonaZaPrebacivanje
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjaRobno_GetByIDVrstaFinDokumenta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjaRobno_GetByIDVrstaFinDokumenta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjaRobno_GetByIDVrstaFinDokumenta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblShemaKnjizenjaRobno table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjaRobno_GetByIDVrstaFinDokumenta
(

	@IDVrstaFinDokumenta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[IDKolonaZaPrebacivanje],
					[KontoZaPrebacivanje],
					[IDVrstaFinDokumenta],
					[DugIliPot],
					[RedBr],
					[SklRobeSklPrema],
					[Maloprodaja]
				FROM
					[dbo].[tblShemaKnjizenjaRobno]
				WHERE
					[IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjaRobno_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjaRobno_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjaRobno_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblShemaKnjizenjaRobno table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjaRobno_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[IDKolonaZaPrebacivanje],
					[KontoZaPrebacivanje],
					[IDVrstaFinDokumenta],
					[DugIliPot],
					[RedBr],
					[SklRobeSklPrema],
					[Maloprodaja]
				FROM
					[dbo].[tblShemaKnjizenjaRobno]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblShemaKnjizenjaRobno_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblShemaKnjizenjaRobno_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblShemaKnjizenjaRobno_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblShemaKnjizenjaRobno table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblShemaKnjizenjaRobno_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDDokumentTip int   = null ,

	@IDKolonaZaPrebacivanje int   = null ,

	@KontoZaPrebacivanje varchar (9)  = null ,

	@IDVrstaFinDokumenta int   = null ,

	@DugIliPot bit   = null ,

	@RedBr int   = null ,

	@SklRobeSklPrema bit   = null ,

	@Maloprodaja bit   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDDokumentTip]
	, [IDKolonaZaPrebacivanje]
	, [KontoZaPrebacivanje]
	, [IDVrstaFinDokumenta]
	, [DugIliPot]
	, [RedBr]
	, [SklRobeSklPrema]
	, [Maloprodaja]
    FROM
	[dbo].[tblShemaKnjizenjaRobno]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDDokumentTip] = @IDDokumentTip OR @IDDokumentTip is null)
	AND ([IDKolonaZaPrebacivanje] = @IDKolonaZaPrebacivanje OR @IDKolonaZaPrebacivanje is null)
	AND ([KontoZaPrebacivanje] = @KontoZaPrebacivanje OR @KontoZaPrebacivanje is null)
	AND ([IDVrstaFinDokumenta] = @IDVrstaFinDokumenta OR @IDVrstaFinDokumenta is null)
	AND ([DugIliPot] = @DugIliPot OR @DugIliPot is null)
	AND ([RedBr] = @RedBr OR @RedBr is null)
	AND ([SklRobeSklPrema] = @SklRobeSklPrema OR @SklRobeSklPrema is null)
	AND ([Maloprodaja] = @Maloprodaja OR @Maloprodaja is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDDokumentTip]
	, [IDKolonaZaPrebacivanje]
	, [KontoZaPrebacivanje]
	, [IDVrstaFinDokumenta]
	, [DugIliPot]
	, [RedBr]
	, [SklRobeSklPrema]
	, [Maloprodaja]
    FROM
	[dbo].[tblShemaKnjizenjaRobno]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDDokumentTip] = @IDDokumentTip AND @IDDokumentTip is not null)
	OR ([IDKolonaZaPrebacivanje] = @IDKolonaZaPrebacivanje AND @IDKolonaZaPrebacivanje is not null)
	OR ([KontoZaPrebacivanje] = @KontoZaPrebacivanje AND @KontoZaPrebacivanje is not null)
	OR ([IDVrstaFinDokumenta] = @IDVrstaFinDokumenta AND @IDVrstaFinDokumenta is not null)
	OR ([DugIliPot] = @DugIliPot AND @DugIliPot is not null)
	OR ([RedBr] = @RedBr AND @RedBr is not null)
	OR ([SklRobeSklPrema] = @SklRobeSklPrema AND @SklRobeSklPrema is not null)
	OR ([Maloprodaja] = @Maloprodaja AND @Maloprodaja is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportPivots_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportPivots_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportPivots_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblReportPivots table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportPivots_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[PivotClass]
				FROM
					[dbo].[tblReportPivots]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportPivots_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportPivots_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportPivots_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblReportPivots table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportPivots_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDReport]'
				SET @SQL = @SQL + ', [PrikazniNaziv]'
				SET @SQL = @SQL + ', [PivotClass]'
				SET @SQL = @SQL + ' FROM [dbo].[tblReportPivots]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDReport],'
				SET @SQL = @SQL + ' [PrikazniNaziv],'
				SET @SQL = @SQL + ' [PivotClass]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblReportPivots]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportPivots_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportPivots_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportPivots_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblReportPivots table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportPivots_Insert
(

	@ID int    OUTPUT,

	@IDReport int   ,

	@PrikazniNaziv nvarchar (200)  ,

	@PivotClass varbinary (MAX)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblReportPivots]
					(
					[IDReport]
					,[PrikazniNaziv]
					,[PivotClass]
					)
				VALUES
					(
					@IDReport
					,@PrikazniNaziv
					,@PivotClass
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportPivots_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportPivots_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportPivots_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblReportPivots table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportPivots_Update
(

	@ID int   ,

	@IDReport int   ,

	@PrikazniNaziv nvarchar (200)  ,

	@PivotClass varbinary (MAX)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblReportPivots]
				SET
					[IDReport] = @IDReport
					,[PrikazniNaziv] = @PrikazniNaziv
					,[PivotClass] = @PivotClass
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportPivots_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportPivots_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportPivots_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblReportPivots table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportPivots_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblReportPivots] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportPivots_GetByIDReport procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportPivots_GetByIDReport') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportPivots_GetByIDReport
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReportPivots table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportPivots_GetByIDReport
(

	@IDReport int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[PivotClass]
				FROM
					[dbo].[tblReportPivots]
				WHERE
					[IDReport] = @IDReport
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportPivots_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportPivots_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportPivots_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReportPivots table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportPivots_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[PivotClass]
				FROM
					[dbo].[tblReportPivots]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportPivots_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportPivots_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportPivots_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblReportPivots table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportPivots_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDReport int   = null ,

	@PrikazniNaziv nvarchar (200)  = null ,

	@PivotClass varbinary (MAX)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDReport]
	, [PrikazniNaziv]
	, [PivotClass]
    FROM
	[dbo].[tblReportPivots]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDReport] = @IDReport OR @IDReport is null)
	AND ([PrikazniNaziv] = @PrikazniNaziv OR @PrikazniNaziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDReport]
	, [PrikazniNaziv]
	, [PivotClass]
    FROM
	[dbo].[tblReportPivots]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDReport] = @IDReport AND @IDReport is not null)
	OR ([PrikazniNaziv] = @PrikazniNaziv AND @PrikazniNaziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRadniNalogVeza_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRadniNalogVeza_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRadniNalogVeza_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblRadniNalogVeza table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRadniNalogVeza_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDParent],
					[IDChild]
				FROM
					[dbo].[tblRadniNalogVeza]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRadniNalogVeza_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRadniNalogVeza_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRadniNalogVeza_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblRadniNalogVeza table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRadniNalogVeza_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDParent]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDParent]'
				SET @SQL = @SQL + ', [IDChild]'
				SET @SQL = @SQL + ' FROM [dbo].[tblRadniNalogVeza]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDParent],'
				SET @SQL = @SQL + ' [IDChild]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblRadniNalogVeza]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRadniNalogVeza_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRadniNalogVeza_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRadniNalogVeza_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblRadniNalogVeza table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRadniNalogVeza_Insert
(

	@IDParent int   ,

	@IDChild int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblRadniNalogVeza]
					(
					[IDParent]
					,[IDChild]
					)
				VALUES
					(
					@IDParent
					,@IDChild
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRadniNalogVeza_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRadniNalogVeza_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRadniNalogVeza_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblRadniNalogVeza table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRadniNalogVeza_Update
(

	@IDParent int   ,

	@OriginalIDParent int   ,

	@IDChild int   ,

	@OriginalIDChild int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblRadniNalogVeza]
				SET
					[IDParent] = @IDParent
					,[IDChild] = @IDChild
				WHERE
[IDParent] = @OriginalIDParent 
AND [IDChild] = @OriginalIDChild 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRadniNalogVeza_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRadniNalogVeza_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRadniNalogVeza_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblRadniNalogVeza table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRadniNalogVeza_Delete
(

	@IDParent int   ,

	@IDChild int   
)
AS


				DELETE FROM [dbo].[tblRadniNalogVeza] WITH (ROWLOCK) 
				WHERE
					[IDParent] = @IDParent
					AND [IDChild] = @IDChild
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRadniNalogVeza_GetByIDChild procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRadniNalogVeza_GetByIDChild') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRadniNalogVeza_GetByIDChild
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRadniNalogVeza table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRadniNalogVeza_GetByIDChild
(

	@IDChild int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDParent],
					[IDChild]
				FROM
					[dbo].[tblRadniNalogVeza]
				WHERE
					[IDChild] = @IDChild
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRadniNalogVeza_GetByIDParent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRadniNalogVeza_GetByIDParent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRadniNalogVeza_GetByIDParent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRadniNalogVeza table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRadniNalogVeza_GetByIDParent
(

	@IDParent int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDParent],
					[IDChild]
				FROM
					[dbo].[tblRadniNalogVeza]
				WHERE
					[IDParent] = @IDParent
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRadniNalogVeza_GetByIDParentIDChild procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRadniNalogVeza_GetByIDParentIDChild') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRadniNalogVeza_GetByIDParentIDChild
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRadniNalogVeza table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRadniNalogVeza_GetByIDParentIDChild
(

	@IDParent int   ,

	@IDChild int   
)
AS


				SELECT
					[IDParent],
					[IDChild]
				FROM
					[dbo].[tblRadniNalogVeza]
				WHERE
					[IDParent] = @IDParent
					AND [IDChild] = @IDChild
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRadniNalogVeza_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRadniNalogVeza_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRadniNalogVeza_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblRadniNalogVeza table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRadniNalogVeza_Find
(

	@SearchUsingOR bit   = null ,

	@IDParent int   = null ,

	@IDChild int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [IDParent]
	, [IDChild]
    FROM
	[dbo].[tblRadniNalogVeza]
    WHERE 
	 ([IDParent] = @IDParent OR @IDParent is null)
	AND ([IDChild] = @IDChild OR @IDChild is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [IDParent]
	, [IDChild]
    FROM
	[dbo].[tblRadniNalogVeza]
    WHERE 
	 ([IDParent] = @IDParent AND @IDParent is not null)
	OR ([IDChild] = @IDChild AND @IDChild is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabat_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabat_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabat_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblRabat table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabat_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[IDProizvodac],
					[IDKategorija],
					[Vrijednost]
				FROM
					[dbo].[tblRabat]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabat_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabat_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabat_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblRabat table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabat_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [IDProizvodac]'
				SET @SQL = @SQL + ', [IDKategorija]'
				SET @SQL = @SQL + ', [Vrijednost]'
				SET @SQL = @SQL + ' FROM [dbo].[tblRabat]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [IDProizvodac],'
				SET @SQL = @SQL + ' [IDKategorija],'
				SET @SQL = @SQL + ' [Vrijednost]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblRabat]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabat_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabat_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabat_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblRabat table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabat_Insert
(

	@ID int    OUTPUT,

	@IDKlijent int   ,

	@IDProizvodac int   ,

	@IDKategorija int   ,

	@Vrijednost real   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblRabat]
					(
					[IDKlijent]
					,[IDProizvodac]
					,[IDKategorija]
					,[Vrijednost]
					)
				VALUES
					(
					@IDKlijent
					,@IDProizvodac
					,@IDKategorija
					,@Vrijednost
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabat_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabat_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabat_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblRabat table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabat_Update
(

	@ID int   ,

	@IDKlijent int   ,

	@IDProizvodac int   ,

	@IDKategorija int   ,

	@Vrijednost real   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblRabat]
				SET
					[IDKlijent] = @IDKlijent
					,[IDProizvodac] = @IDProizvodac
					,[IDKategorija] = @IDKategorija
					,[Vrijednost] = @Vrijednost
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabat_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabat_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabat_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblRabat table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabat_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblRabat] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabat_GetByIDKategorija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabat_GetByIDKategorija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabat_GetByIDKategorija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRabat table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabat_GetByIDKategorija
(

	@IDKategorija int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[IDProizvodac],
					[IDKategorija],
					[Vrijednost]
				FROM
					[dbo].[tblRabat]
				WHERE
					[IDKategorija] = @IDKategorija
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabat_GetByIDKlijent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabat_GetByIDKlijent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabat_GetByIDKlijent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRabat table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabat_GetByIDKlijent
(

	@IDKlijent int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[IDProizvodac],
					[IDKategorija],
					[Vrijednost]
				FROM
					[dbo].[tblRabat]
				WHERE
					[IDKlijent] = @IDKlijent
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabat_GetByIDProizvodac procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabat_GetByIDProizvodac') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabat_GetByIDProizvodac
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRabat table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabat_GetByIDProizvodac
(

	@IDProizvodac int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[IDProizvodac],
					[IDKategorija],
					[Vrijednost]
				FROM
					[dbo].[tblRabat]
				WHERE
					[IDProizvodac] = @IDProizvodac
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabat_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabat_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabat_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRabat table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabat_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDKlijent],
					[IDProizvodac],
					[IDKategorija],
					[Vrijednost]
				FROM
					[dbo].[tblRabat]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabat_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabat_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabat_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblRabat table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabat_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDKlijent int   = null ,

	@IDProizvodac int   = null ,

	@IDKategorija int   = null ,

	@Vrijednost real   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDKlijent]
	, [IDProizvodac]
	, [IDKategorija]
	, [Vrijednost]
    FROM
	[dbo].[tblRabat]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDKlijent] = @IDKlijent OR @IDKlijent is null)
	AND ([IDProizvodac] = @IDProizvodac OR @IDProizvodac is null)
	AND ([IDKategorija] = @IDKategorija OR @IDKategorija is null)
	AND ([Vrijednost] = @Vrijednost OR @Vrijednost is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDKlijent]
	, [IDProizvodac]
	, [IDKategorija]
	, [Vrijednost]
    FROM
	[dbo].[tblRabat]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDKlijent] = @IDKlijent AND @IDKlijent is not null)
	OR ([IDProizvodac] = @IDProizvodac AND @IDProizvodac is not null)
	OR ([IDKategorija] = @IDKategorija AND @IDKategorija is not null)
	OR ([Vrijednost] = @Vrijednost AND @Vrijednost is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaOstalo_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaOstalo_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaOstalo_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblPutniNalogStavkaOstalo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaOstalo_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[Grupa],
					[Opis],
					[IDValuta],
					[IznosValuta],
					[IznosKuna],
					[Blagajna],
					[IDKontoOstalo],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaOstalo]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaOstalo_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaOstalo_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaOstalo_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblPutniNalogStavkaOstalo table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaOstalo_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDPutniNalog]'
				SET @SQL = @SQL + ', [Grupa]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [IDValuta]'
				SET @SQL = @SQL + ', [IznosValuta]'
				SET @SQL = @SQL + ', [IznosKuna]'
				SET @SQL = @SQL + ', [Blagajna]'
				SET @SQL = @SQL + ', [IDKontoOstalo]'
				SET @SQL = @SQL + ', [IDBlagajnaStavka]'
				SET @SQL = @SQL + ' FROM [fin].[tblPutniNalogStavkaOstalo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDPutniNalog],'
				SET @SQL = @SQL + ' [Grupa],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [IDValuta],'
				SET @SQL = @SQL + ' [IznosValuta],'
				SET @SQL = @SQL + ' [IznosKuna],'
				SET @SQL = @SQL + ' [Blagajna],'
				SET @SQL = @SQL + ' [IDKontoOstalo],'
				SET @SQL = @SQL + ' [IDBlagajnaStavka]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblPutniNalogStavkaOstalo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaOstalo_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaOstalo_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaOstalo_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblPutniNalogStavkaOstalo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaOstalo_Insert
(

	@ID int    OUTPUT,

	@IDPutniNalog int   ,

	@Grupa nvarchar (150)  ,

	@Opis nvarchar (150)  ,

	@IDValuta int   ,

	@IznosValuta money   ,

	@IznosKuna money   ,

	@Blagajna bit   ,

	@IDKontoOstalo int   ,

	@IDBlagajnaStavka int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblPutniNalogStavkaOstalo]
					(
					[IDPutniNalog]
					,[Grupa]
					,[Opis]
					,[IDValuta]
					,[IznosValuta]
					,[IznosKuna]
					,[Blagajna]
					,[IDKontoOstalo]
					,[IDBlagajnaStavka]
					)
				VALUES
					(
					@IDPutniNalog
					,@Grupa
					,@Opis
					,@IDValuta
					,@IznosValuta
					,@IznosKuna
					,@Blagajna
					,@IDKontoOstalo
					,@IDBlagajnaStavka
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaOstalo_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaOstalo_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaOstalo_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblPutniNalogStavkaOstalo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaOstalo_Update
(

	@ID int   ,

	@IDPutniNalog int   ,

	@Grupa nvarchar (150)  ,

	@Opis nvarchar (150)  ,

	@IDValuta int   ,

	@IznosValuta money   ,

	@IznosKuna money   ,

	@Blagajna bit   ,

	@IDKontoOstalo int   ,

	@IDBlagajnaStavka int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblPutniNalogStavkaOstalo]
				SET
					[IDPutniNalog] = @IDPutniNalog
					,[Grupa] = @Grupa
					,[Opis] = @Opis
					,[IDValuta] = @IDValuta
					,[IznosValuta] = @IznosValuta
					,[IznosKuna] = @IznosKuna
					,[Blagajna] = @Blagajna
					,[IDKontoOstalo] = @IDKontoOstalo
					,[IDBlagajnaStavka] = @IDBlagajnaStavka
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaOstalo_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaOstalo_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaOstalo_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblPutniNalogStavkaOstalo table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaOstalo_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblPutniNalogStavkaOstalo] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaOstalo_GetByIDKontoOstalo procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaOstalo_GetByIDKontoOstalo') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaOstalo_GetByIDKontoOstalo
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaOstalo table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaOstalo_GetByIDKontoOstalo
(

	@IDKontoOstalo int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[Grupa],
					[Opis],
					[IDValuta],
					[IznosValuta],
					[IznosKuna],
					[Blagajna],
					[IDKontoOstalo],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaOstalo]
				WHERE
					[IDKontoOstalo] = @IDKontoOstalo
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaOstalo_GetByIDPutniNalog procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaOstalo_GetByIDPutniNalog') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaOstalo_GetByIDPutniNalog
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaOstalo table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaOstalo_GetByIDPutniNalog
(

	@IDPutniNalog int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[Grupa],
					[Opis],
					[IDValuta],
					[IznosValuta],
					[IznosKuna],
					[Blagajna],
					[IDKontoOstalo],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaOstalo]
				WHERE
					[IDPutniNalog] = @IDPutniNalog
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaOstalo_GetByIDValuta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaOstalo_GetByIDValuta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaOstalo_GetByIDValuta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaOstalo table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaOstalo_GetByIDValuta
(

	@IDValuta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[Grupa],
					[Opis],
					[IDValuta],
					[IznosValuta],
					[IznosKuna],
					[Blagajna],
					[IDKontoOstalo],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaOstalo]
				WHERE
					[IDValuta] = @IDValuta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaOstalo_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaOstalo_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaOstalo_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaOstalo table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaOstalo_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDPutniNalog],
					[Grupa],
					[Opis],
					[IDValuta],
					[IznosValuta],
					[IznosKuna],
					[Blagajna],
					[IDKontoOstalo],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaOstalo]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaOstalo_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaOstalo_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaOstalo_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblPutniNalogStavkaOstalo table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaOstalo_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDPutniNalog int   = null ,

	@Grupa nvarchar (150)  = null ,

	@Opis nvarchar (150)  = null ,

	@IDValuta int   = null ,

	@IznosValuta money   = null ,

	@IznosKuna money   = null ,

	@Blagajna bit   = null ,

	@IDKontoOstalo int   = null ,

	@IDBlagajnaStavka int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDPutniNalog]
	, [Grupa]
	, [Opis]
	, [IDValuta]
	, [IznosValuta]
	, [IznosKuna]
	, [Blagajna]
	, [IDKontoOstalo]
	, [IDBlagajnaStavka]
    FROM
	[fin].[tblPutniNalogStavkaOstalo]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDPutniNalog] = @IDPutniNalog OR @IDPutniNalog is null)
	AND ([Grupa] = @Grupa OR @Grupa is null)
	AND ([Opis] = @Opis OR @Opis is null)
	AND ([IDValuta] = @IDValuta OR @IDValuta is null)
	AND ([IznosValuta] = @IznosValuta OR @IznosValuta is null)
	AND ([IznosKuna] = @IznosKuna OR @IznosKuna is null)
	AND ([Blagajna] = @Blagajna OR @Blagajna is null)
	AND ([IDKontoOstalo] = @IDKontoOstalo OR @IDKontoOstalo is null)
	AND ([IDBlagajnaStavka] = @IDBlagajnaStavka OR @IDBlagajnaStavka is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDPutniNalog]
	, [Grupa]
	, [Opis]
	, [IDValuta]
	, [IznosValuta]
	, [IznosKuna]
	, [Blagajna]
	, [IDKontoOstalo]
	, [IDBlagajnaStavka]
    FROM
	[fin].[tblPutniNalogStavkaOstalo]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDPutniNalog] = @IDPutniNalog AND @IDPutniNalog is not null)
	OR ([Grupa] = @Grupa AND @Grupa is not null)
	OR ([Opis] = @Opis AND @Opis is not null)
	OR ([IDValuta] = @IDValuta AND @IDValuta is not null)
	OR ([IznosValuta] = @IznosValuta AND @IznosValuta is not null)
	OR ([IznosKuna] = @IznosKuna AND @IznosKuna is not null)
	OR ([Blagajna] = @Blagajna AND @Blagajna is not null)
	OR ([IDKontoOstalo] = @IDKontoOstalo AND @IDKontoOstalo is not null)
	OR ([IDBlagajnaStavka] = @IDBlagajnaStavka AND @IDBlagajnaStavka is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaPrijevoz_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaPrijevoz_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaPrijevoz_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblPutniNalogStavkaPrijevoz table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaPrijevoz_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[IDVozilo],
					[RelacijaOd],
					[RelacijaDo],
					[Kilometara],
					[BrojiloPocetak],
					[BrojiloKraj],
					[PoKm],
					[VoziloOpis],
					[Iznos],
					[IDKontoPrijevoza],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaPrijevoz]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaPrijevoz_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaPrijevoz_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaPrijevoz_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblPutniNalogStavkaPrijevoz table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaPrijevoz_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDPutniNalog]'
				SET @SQL = @SQL + ', [IDVozilo]'
				SET @SQL = @SQL + ', [RelacijaOd]'
				SET @SQL = @SQL + ', [RelacijaDo]'
				SET @SQL = @SQL + ', [Kilometara]'
				SET @SQL = @SQL + ', [BrojiloPocetak]'
				SET @SQL = @SQL + ', [BrojiloKraj]'
				SET @SQL = @SQL + ', [PoKm]'
				SET @SQL = @SQL + ', [VoziloOpis]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [IDKontoPrijevoza]'
				SET @SQL = @SQL + ', [IDBlagajnaStavka]'
				SET @SQL = @SQL + ' FROM [fin].[tblPutniNalogStavkaPrijevoz]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDPutniNalog],'
				SET @SQL = @SQL + ' [IDVozilo],'
				SET @SQL = @SQL + ' [RelacijaOd],'
				SET @SQL = @SQL + ' [RelacijaDo],'
				SET @SQL = @SQL + ' [Kilometara],'
				SET @SQL = @SQL + ' [BrojiloPocetak],'
				SET @SQL = @SQL + ' [BrojiloKraj],'
				SET @SQL = @SQL + ' [PoKm],'
				SET @SQL = @SQL + ' [VoziloOpis],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [IDKontoPrijevoza],'
				SET @SQL = @SQL + ' [IDBlagajnaStavka]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblPutniNalogStavkaPrijevoz]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaPrijevoz_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaPrijevoz_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaPrijevoz_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblPutniNalogStavkaPrijevoz table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaPrijevoz_Insert
(

	@ID int    OUTPUT,

	@IDPutniNalog int   ,

	@IDVozilo int   ,

	@RelacijaOd nvarchar (150)  ,

	@RelacijaDo nvarchar (150)  ,

	@Kilometara money   ,

	@BrojiloPocetak money   ,

	@BrojiloKraj money   ,

	@PoKm money   ,

	@VoziloOpis nvarchar (150)  ,

	@Iznos money    OUTPUT,

	@IDKontoPrijevoza int   ,

	@IDBlagajnaStavka int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblPutniNalogStavkaPrijevoz]
					(
					[IDPutniNalog]
					,[IDVozilo]
					,[RelacijaOd]
					,[RelacijaDo]
					,[Kilometara]
					,[BrojiloPocetak]
					,[BrojiloKraj]
					,[PoKm]
					,[VoziloOpis]
					,[IDKontoPrijevoza]
					,[IDBlagajnaStavka]
					)
				VALUES
					(
					@IDPutniNalog
					,@IDVozilo
					,@RelacijaOd
					,@RelacijaDo
					,@Kilometara
					,@BrojiloPocetak
					,@BrojiloKraj
					,@PoKm
					,@VoziloOpis
					,@IDKontoPrijevoza
					,@IDBlagajnaStavka
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
				-- Select computed columns into output parameters
				SELECT
 @Iznos = [Iznos]
				FROM
					[fin].[tblPutniNalogStavkaPrijevoz]
				WHERE
[ID] = @ID 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaPrijevoz_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaPrijevoz_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaPrijevoz_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblPutniNalogStavkaPrijevoz table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaPrijevoz_Update
(

	@ID int   ,

	@IDPutniNalog int   ,

	@IDVozilo int   ,

	@RelacijaOd nvarchar (150)  ,

	@RelacijaDo nvarchar (150)  ,

	@Kilometara money   ,

	@BrojiloPocetak money   ,

	@BrojiloKraj money   ,

	@PoKm money   ,

	@VoziloOpis nvarchar (150)  ,

	@Iznos money    OUTPUT,

	@IDKontoPrijevoza int   ,

	@IDBlagajnaStavka int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblPutniNalogStavkaPrijevoz]
				SET
					[IDPutniNalog] = @IDPutniNalog
					,[IDVozilo] = @IDVozilo
					,[RelacijaOd] = @RelacijaOd
					,[RelacijaDo] = @RelacijaDo
					,[Kilometara] = @Kilometara
					,[BrojiloPocetak] = @BrojiloPocetak
					,[BrojiloKraj] = @BrojiloKraj
					,[PoKm] = @PoKm
					,[VoziloOpis] = @VoziloOpis
					,[IDKontoPrijevoza] = @IDKontoPrijevoza
					,[IDBlagajnaStavka] = @IDBlagajnaStavka
				WHERE
[ID] = @ID 
				
				
				-- Select computed columns into output parameters
				SELECT
 @Iznos = [Iznos]
				FROM
					[fin].[tblPutniNalogStavkaPrijevoz]
				WHERE
[ID] = @ID 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaPrijevoz_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaPrijevoz_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaPrijevoz_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblPutniNalogStavkaPrijevoz table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaPrijevoz_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblPutniNalogStavkaPrijevoz] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaPrijevoz_GetByIDKontoPrijevoza procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaPrijevoz_GetByIDKontoPrijevoza') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaPrijevoz_GetByIDKontoPrijevoza
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaPrijevoz table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaPrijevoz_GetByIDKontoPrijevoza
(

	@IDKontoPrijevoza int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[IDVozilo],
					[RelacijaOd],
					[RelacijaDo],
					[Kilometara],
					[BrojiloPocetak],
					[BrojiloKraj],
					[PoKm],
					[VoziloOpis],
					[Iznos],
					[IDKontoPrijevoza],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaPrijevoz]
				WHERE
					[IDKontoPrijevoza] = @IDKontoPrijevoza
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaPrijevoz_GetByIDPutniNalog procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaPrijevoz_GetByIDPutniNalog') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaPrijevoz_GetByIDPutniNalog
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaPrijevoz table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaPrijevoz_GetByIDPutniNalog
(

	@IDPutniNalog int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[IDVozilo],
					[RelacijaOd],
					[RelacijaDo],
					[Kilometara],
					[BrojiloPocetak],
					[BrojiloKraj],
					[PoKm],
					[VoziloOpis],
					[Iznos],
					[IDKontoPrijevoza],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaPrijevoz]
				WHERE
					[IDPutniNalog] = @IDPutniNalog
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaPrijevoz_GetByIDVozilo procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaPrijevoz_GetByIDVozilo') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaPrijevoz_GetByIDVozilo
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaPrijevoz table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaPrijevoz_GetByIDVozilo
(

	@IDVozilo int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDPutniNalog],
					[IDVozilo],
					[RelacijaOd],
					[RelacijaDo],
					[Kilometara],
					[BrojiloPocetak],
					[BrojiloKraj],
					[PoKm],
					[VoziloOpis],
					[Iznos],
					[IDKontoPrijevoza],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaPrijevoz]
				WHERE
					[IDVozilo] = @IDVozilo
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaPrijevoz_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaPrijevoz_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaPrijevoz_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblPutniNalogStavkaPrijevoz table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaPrijevoz_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDPutniNalog],
					[IDVozilo],
					[RelacijaOd],
					[RelacijaDo],
					[Kilometara],
					[BrojiloPocetak],
					[BrojiloKraj],
					[PoKm],
					[VoziloOpis],
					[Iznos],
					[IDKontoPrijevoza],
					[IDBlagajnaStavka]
				FROM
					[fin].[tblPutniNalogStavkaPrijevoz]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblPutniNalogStavkaPrijevoz_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblPutniNalogStavkaPrijevoz_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblPutniNalogStavkaPrijevoz_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblPutniNalogStavkaPrijevoz table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblPutniNalogStavkaPrijevoz_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDPutniNalog int   = null ,

	@IDVozilo int   = null ,

	@RelacijaOd nvarchar (150)  = null ,

	@RelacijaDo nvarchar (150)  = null ,

	@Kilometara money   = null ,

	@BrojiloPocetak money   = null ,

	@BrojiloKraj money   = null ,

	@PoKm money   = null ,

	@VoziloOpis nvarchar (150)  = null ,

	@Iznos money   = null ,

	@IDKontoPrijevoza int   = null ,

	@IDBlagajnaStavka int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDPutniNalog]
	, [IDVozilo]
	, [RelacijaOd]
	, [RelacijaDo]
	, [Kilometara]
	, [BrojiloPocetak]
	, [BrojiloKraj]
	, [PoKm]
	, [VoziloOpis]
	, [Iznos]
	, [IDKontoPrijevoza]
	, [IDBlagajnaStavka]
    FROM
	[fin].[tblPutniNalogStavkaPrijevoz]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDPutniNalog] = @IDPutniNalog OR @IDPutniNalog is null)
	AND ([IDVozilo] = @IDVozilo OR @IDVozilo is null)
	AND ([RelacijaOd] = @RelacijaOd OR @RelacijaOd is null)
	AND ([RelacijaDo] = @RelacijaDo OR @RelacijaDo is null)
	AND ([Kilometara] = @Kilometara OR @Kilometara is null)
	AND ([BrojiloPocetak] = @BrojiloPocetak OR @BrojiloPocetak is null)
	AND ([BrojiloKraj] = @BrojiloKraj OR @BrojiloKraj is null)
	AND ([PoKm] = @PoKm OR @PoKm is null)
	AND ([VoziloOpis] = @VoziloOpis OR @VoziloOpis is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
	AND ([IDKontoPrijevoza] = @IDKontoPrijevoza OR @IDKontoPrijevoza is null)
	AND ([IDBlagajnaStavka] = @IDBlagajnaStavka OR @IDBlagajnaStavka is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDPutniNalog]
	, [IDVozilo]
	, [RelacijaOd]
	, [RelacijaDo]
	, [Kilometara]
	, [BrojiloPocetak]
	, [BrojiloKraj]
	, [PoKm]
	, [VoziloOpis]
	, [Iznos]
	, [IDKontoPrijevoza]
	, [IDBlagajnaStavka]
    FROM
	[fin].[tblPutniNalogStavkaPrijevoz]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDPutniNalog] = @IDPutniNalog AND @IDPutniNalog is not null)
	OR ([IDVozilo] = @IDVozilo AND @IDVozilo is not null)
	OR ([RelacijaOd] = @RelacijaOd AND @RelacijaOd is not null)
	OR ([RelacijaDo] = @RelacijaDo AND @RelacijaDo is not null)
	OR ([Kilometara] = @Kilometara AND @Kilometara is not null)
	OR ([BrojiloPocetak] = @BrojiloPocetak AND @BrojiloPocetak is not null)
	OR ([BrojiloKraj] = @BrojiloKraj AND @BrojiloKraj is not null)
	OR ([PoKm] = @PoKm AND @PoKm is not null)
	OR ([VoziloOpis] = @VoziloOpis AND @VoziloOpis is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	OR ([IDKontoPrijevoza] = @IDKontoPrijevoza AND @IDKontoPrijevoza is not null)
	OR ([IDBlagajnaStavka] = @IDBlagajnaStavka AND @IDBlagajnaStavka is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadniOdnosTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadniOdnosTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadniOdnosTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblRadniOdnosTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadniOdnosTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblRadniOdnosTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadniOdnosTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadniOdnosTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadniOdnosTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblRadniOdnosTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadniOdnosTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [pla].[tblRadniOdnosTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblRadniOdnosTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadniOdnosTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadniOdnosTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadniOdnosTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblRadniOdnosTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadniOdnosTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblRadniOdnosTip]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadniOdnosTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadniOdnosTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadniOdnosTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblRadniOdnosTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadniOdnosTip_Update
(

	@ID int   ,

	@Naziv nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblRadniOdnosTip]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadniOdnosTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadniOdnosTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadniOdnosTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblRadniOdnosTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadniOdnosTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblRadniOdnosTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadniOdnosTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadniOdnosTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadniOdnosTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRadniOdnosTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadniOdnosTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblRadniOdnosTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadniOdnosTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadniOdnosTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadniOdnosTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblRadniOdnosTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadniOdnosTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (100)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblRadniOdnosTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblRadniOdnosTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabatSpec_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabatSpec_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabatSpec_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblRabatSpec table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabatSpec_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDRabat],
					[IDSpec],
					[Vrijed]
				FROM
					[dbo].[tblRabatSpec]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabatSpec_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabatSpec_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabatSpec_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblRabatSpec table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabatSpec_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDRabat]'
				SET @SQL = @SQL + ', [IDSpec]'
				SET @SQL = @SQL + ', [Vrijed]'
				SET @SQL = @SQL + ' FROM [dbo].[tblRabatSpec]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDRabat],'
				SET @SQL = @SQL + ' [IDSpec],'
				SET @SQL = @SQL + ' [Vrijed]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblRabatSpec]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabatSpec_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabatSpec_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabatSpec_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblRabatSpec table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabatSpec_Insert
(

	@ID int    OUTPUT,

	@IDRabat int   ,

	@IDSpec int   ,

	@Vrijed nvarchar (500)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblRabatSpec]
					(
					[IDRabat]
					,[IDSpec]
					,[Vrijed]
					)
				VALUES
					(
					@IDRabat
					,@IDSpec
					,@Vrijed
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabatSpec_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabatSpec_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabatSpec_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblRabatSpec table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabatSpec_Update
(

	@ID int   ,

	@IDRabat int   ,

	@IDSpec int   ,

	@Vrijed nvarchar (500)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblRabatSpec]
				SET
					[IDRabat] = @IDRabat
					,[IDSpec] = @IDSpec
					,[Vrijed] = @Vrijed
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabatSpec_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabatSpec_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabatSpec_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblRabatSpec table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabatSpec_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblRabatSpec] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabatSpec_GetByIDSpec procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabatSpec_GetByIDSpec') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabatSpec_GetByIDSpec
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRabatSpec table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabatSpec_GetByIDSpec
(

	@IDSpec int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDRabat],
					[IDSpec],
					[Vrijed]
				FROM
					[dbo].[tblRabatSpec]
				WHERE
					[IDSpec] = @IDSpec
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabatSpec_GetByIDRabat procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabatSpec_GetByIDRabat') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabatSpec_GetByIDRabat
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRabatSpec table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabatSpec_GetByIDRabat
(

	@IDRabat int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDRabat],
					[IDSpec],
					[Vrijed]
				FROM
					[dbo].[tblRabatSpec]
				WHERE
					[IDRabat] = @IDRabat
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabatSpec_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabatSpec_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabatSpec_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRabatSpec table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabatSpec_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDRabat],
					[IDSpec],
					[Vrijed]
				FROM
					[dbo].[tblRabatSpec]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRabatSpec_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRabatSpec_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRabatSpec_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblRabatSpec table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRabatSpec_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDRabat int   = null ,

	@IDSpec int   = null ,

	@Vrijed nvarchar (500)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDRabat]
	, [IDSpec]
	, [Vrijed]
    FROM
	[dbo].[tblRabatSpec]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDRabat] = @IDRabat OR @IDRabat is null)
	AND ([IDSpec] = @IDSpec OR @IDSpec is null)
	AND ([Vrijed] = @Vrijed OR @Vrijed is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDRabat]
	, [IDSpec]
	, [Vrijed]
    FROM
	[dbo].[tblRabatSpec]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDRabat] = @IDRabat AND @IDRabat is not null)
	OR ([IDSpec] = @IDSpec AND @IDSpec is not null)
	OR ([Vrijed] = @Vrijed AND @Vrijed is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadnoMjesto_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadnoMjesto_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadnoMjesto_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblRadnoMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadnoMjesto_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblRadnoMjesto]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadnoMjesto_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadnoMjesto_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadnoMjesto_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblRadnoMjesto table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadnoMjesto_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [pla].[tblRadnoMjesto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblRadnoMjesto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadnoMjesto_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadnoMjesto_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadnoMjesto_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblRadnoMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadnoMjesto_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (300)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblRadnoMjesto]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadnoMjesto_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadnoMjesto_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadnoMjesto_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblRadnoMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadnoMjesto_Update
(

	@ID int   ,

	@Naziv nvarchar (300)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblRadnoMjesto]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadnoMjesto_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadnoMjesto_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadnoMjesto_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblRadnoMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadnoMjesto_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblRadnoMjesto] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadnoMjesto_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadnoMjesto_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadnoMjesto_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRadnoMjesto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadnoMjesto_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblRadnoMjesto]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblRadnoMjesto_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblRadnoMjesto_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblRadnoMjesto_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblRadnoMjesto table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblRadnoMjesto_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (300)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblRadnoMjesto]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblRadnoMjesto]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumnaTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumnaTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumnaTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblReportKolumnaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumnaTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Opis]
				FROM
					[dbo].[tblReportKolumnaTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumnaTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumnaTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumnaTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblReportKolumnaTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumnaTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ' FROM [dbo].[tblReportKolumnaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Opis]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblReportKolumnaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumnaTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumnaTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumnaTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblReportKolumnaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumnaTip_Insert
(

	@ID int   ,

	@Naziv varchar (20)  ,

	@Opis varchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblReportKolumnaTip]
					(
					[ID]
					,[Naziv]
					,[Opis]
					)
				VALUES
					(
					@ID
					,@Naziv
					,@Opis
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumnaTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumnaTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumnaTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblReportKolumnaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumnaTip_Update
(

	@ID int   ,

	@OriginalID int   ,

	@Naziv varchar (20)  ,

	@Opis varchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblReportKolumnaTip]
				SET
					[ID] = @ID
					,[Naziv] = @Naziv
					,[Opis] = @Opis
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumnaTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumnaTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumnaTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblReportKolumnaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumnaTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblReportKolumnaTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumnaTip_GetByNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumnaTip_GetByNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumnaTip_GetByNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReportKolumnaTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumnaTip_GetByNaziv
(

	@Naziv varchar (20)  
)
AS


				SELECT
					[ID],
					[Naziv],
					[Opis]
				FROM
					[dbo].[tblReportKolumnaTip]
				WHERE
					[Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumnaTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumnaTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumnaTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReportKolumnaTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumnaTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[Opis]
				FROM
					[dbo].[tblReportKolumnaTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumnaTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumnaTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumnaTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblReportKolumnaTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumnaTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv varchar (20)  = null ,

	@Opis varchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Opis]
    FROM
	[dbo].[tblReportKolumnaTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Opis] = @Opis OR @Opis is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Opis]
    FROM
	[dbo].[tblReportKolumnaTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Opis] = @Opis AND @Opis is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumna_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumna_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumna_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblReportKolumna table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumna_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[NazivUQuery],
					[WhereUpit],
					[IDReportKolumnaTip],
					[RedBr],
					[NazivPolja],
					[Parametar],
					[SelectUpit]
				FROM
					[dbo].[tblReportKolumna]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumna_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumna_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumna_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblReportKolumna table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumna_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDReport]'
				SET @SQL = @SQL + ', [PrikazniNaziv]'
				SET @SQL = @SQL + ', [NazivUQuery]'
				SET @SQL = @SQL + ', [WhereUpit]'
				SET @SQL = @SQL + ', [IDReportKolumnaTip]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [NazivPolja]'
				SET @SQL = @SQL + ', [Parametar]'
				SET @SQL = @SQL + ', [SelectUpit]'
				SET @SQL = @SQL + ' FROM [dbo].[tblReportKolumna]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDReport],'
				SET @SQL = @SQL + ' [PrikazniNaziv],'
				SET @SQL = @SQL + ' [NazivUQuery],'
				SET @SQL = @SQL + ' [WhereUpit],'
				SET @SQL = @SQL + ' [IDReportKolumnaTip],'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [NazivPolja],'
				SET @SQL = @SQL + ' [Parametar],'
				SET @SQL = @SQL + ' [SelectUpit]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblReportKolumna]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumna_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumna_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumna_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblReportKolumna table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumna_Insert
(

	@ID int    OUTPUT,

	@IDReport int   ,

	@PrikazniNaziv nvarchar (50)  ,

	@NazivUQuery nvarchar (100)  ,

	@WhereUpit smallint   ,

	@IDReportKolumnaTip int   ,

	@RedBr int   ,

	@NazivPolja nvarchar (100)  ,

	@Parametar bit   ,

	@SelectUpit nvarchar (400)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblReportKolumna]
					(
					[IDReport]
					,[PrikazniNaziv]
					,[NazivUQuery]
					,[WhereUpit]
					,[IDReportKolumnaTip]
					,[RedBr]
					,[NazivPolja]
					,[Parametar]
					,[SelectUpit]
					)
				VALUES
					(
					@IDReport
					,@PrikazniNaziv
					,@NazivUQuery
					,@WhereUpit
					,@IDReportKolumnaTip
					,@RedBr
					,@NazivPolja
					,@Parametar
					,@SelectUpit
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumna_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumna_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumna_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblReportKolumna table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumna_Update
(

	@ID int   ,

	@IDReport int   ,

	@PrikazniNaziv nvarchar (50)  ,

	@NazivUQuery nvarchar (100)  ,

	@WhereUpit smallint   ,

	@IDReportKolumnaTip int   ,

	@RedBr int   ,

	@NazivPolja nvarchar (100)  ,

	@Parametar bit   ,

	@SelectUpit nvarchar (400)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblReportKolumna]
				SET
					[IDReport] = @IDReport
					,[PrikazniNaziv] = @PrikazniNaziv
					,[NazivUQuery] = @NazivUQuery
					,[WhereUpit] = @WhereUpit
					,[IDReportKolumnaTip] = @IDReportKolumnaTip
					,[RedBr] = @RedBr
					,[NazivPolja] = @NazivPolja
					,[Parametar] = @Parametar
					,[SelectUpit] = @SelectUpit
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumna_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumna_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumna_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblReportKolumna table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumna_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblReportKolumna] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumna_GetByIDReport procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumna_GetByIDReport') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumna_GetByIDReport
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReportKolumna table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumna_GetByIDReport
(

	@IDReport int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[NazivUQuery],
					[WhereUpit],
					[IDReportKolumnaTip],
					[RedBr],
					[NazivPolja],
					[Parametar],
					[SelectUpit]
				FROM
					[dbo].[tblReportKolumna]
				WHERE
					[IDReport] = @IDReport
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumna_GetByIDReportKolumnaTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumna_GetByIDReportKolumnaTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumna_GetByIDReportKolumnaTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReportKolumna table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumna_GetByIDReportKolumnaTip
(

	@IDReportKolumnaTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[NazivUQuery],
					[WhereUpit],
					[IDReportKolumnaTip],
					[RedBr],
					[NazivPolja],
					[Parametar],
					[SelectUpit]
				FROM
					[dbo].[tblReportKolumna]
				WHERE
					[IDReportKolumnaTip] = @IDReportKolumnaTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumna_GetByIDReportRedBr procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumna_GetByIDReportRedBr') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumna_GetByIDReportRedBr
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReportKolumna table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumna_GetByIDReportRedBr
(

	@IDReport int   ,

	@RedBr int   
)
AS


				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[NazivUQuery],
					[WhereUpit],
					[IDReportKolumnaTip],
					[RedBr],
					[NazivPolja],
					[Parametar],
					[SelectUpit]
				FROM
					[dbo].[tblReportKolumna]
				WHERE
					[IDReport] = @IDReport
					AND [RedBr] = @RedBr
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumna_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumna_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumna_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReportKolumna table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumna_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[NazivUQuery],
					[WhereUpit],
					[IDReportKolumnaTip],
					[RedBr],
					[NazivPolja],
					[Parametar],
					[SelectUpit]
				FROM
					[dbo].[tblReportKolumna]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportKolumna_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportKolumna_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportKolumna_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblReportKolumna table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportKolumna_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDReport int   = null ,

	@PrikazniNaziv nvarchar (50)  = null ,

	@NazivUQuery nvarchar (100)  = null ,

	@WhereUpit smallint   = null ,

	@IDReportKolumnaTip int   = null ,

	@RedBr int   = null ,

	@NazivPolja nvarchar (100)  = null ,

	@Parametar bit   = null ,

	@SelectUpit nvarchar (400)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDReport]
	, [PrikazniNaziv]
	, [NazivUQuery]
	, [WhereUpit]
	, [IDReportKolumnaTip]
	, [RedBr]
	, [NazivPolja]
	, [Parametar]
	, [SelectUpit]
    FROM
	[dbo].[tblReportKolumna]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDReport] = @IDReport OR @IDReport is null)
	AND ([PrikazniNaziv] = @PrikazniNaziv OR @PrikazniNaziv is null)
	AND ([NazivUQuery] = @NazivUQuery OR @NazivUQuery is null)
	AND ([WhereUpit] = @WhereUpit OR @WhereUpit is null)
	AND ([IDReportKolumnaTip] = @IDReportKolumnaTip OR @IDReportKolumnaTip is null)
	AND ([RedBr] = @RedBr OR @RedBr is null)
	AND ([NazivPolja] = @NazivPolja OR @NazivPolja is null)
	AND ([Parametar] = @Parametar OR @Parametar is null)
	AND ([SelectUpit] = @SelectUpit OR @SelectUpit is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDReport]
	, [PrikazniNaziv]
	, [NazivUQuery]
	, [WhereUpit]
	, [IDReportKolumnaTip]
	, [RedBr]
	, [NazivPolja]
	, [Parametar]
	, [SelectUpit]
    FROM
	[dbo].[tblReportKolumna]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDReport] = @IDReport AND @IDReport is not null)
	OR ([PrikazniNaziv] = @PrikazniNaziv AND @PrikazniNaziv is not null)
	OR ([NazivUQuery] = @NazivUQuery AND @NazivUQuery is not null)
	OR ([WhereUpit] = @WhereUpit AND @WhereUpit is not null)
	OR ([IDReportKolumnaTip] = @IDReportKolumnaTip AND @IDReportKolumnaTip is not null)
	OR ([RedBr] = @RedBr AND @RedBr is not null)
	OR ([NazivPolja] = @NazivPolja AND @NazivPolja is not null)
	OR ([Parametar] = @Parametar AND @Parametar is not null)
	OR ([SelectUpit] = @SelectUpit AND @SelectUpit is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportiServer_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportiServer_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportiServer_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblReportiServer table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportiServer_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[Izvjestaj]
				FROM
					[dbo].[tblReportiServer]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportiServer_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportiServer_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportiServer_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblReportiServer table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportiServer_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDReport]'
				SET @SQL = @SQL + ', [PrikazniNaziv]'
				SET @SQL = @SQL + ', [Izvjestaj]'
				SET @SQL = @SQL + ' FROM [dbo].[tblReportiServer]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDReport],'
				SET @SQL = @SQL + ' [PrikazniNaziv],'
				SET @SQL = @SQL + ' [Izvjestaj]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblReportiServer]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportiServer_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportiServer_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportiServer_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblReportiServer table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportiServer_Insert
(

	@ID int    OUTPUT,

	@IDReport int   ,

	@PrikazniNaziv nvarchar (200)  ,

	@Izvjestaj varbinary (MAX)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblReportiServer]
					(
					[IDReport]
					,[PrikazniNaziv]
					,[Izvjestaj]
					)
				VALUES
					(
					@IDReport
					,@PrikazniNaziv
					,@Izvjestaj
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportiServer_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportiServer_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportiServer_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblReportiServer table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportiServer_Update
(

	@ID int   ,

	@IDReport int   ,

	@PrikazniNaziv nvarchar (200)  ,

	@Izvjestaj varbinary (MAX)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblReportiServer]
				SET
					[IDReport] = @IDReport
					,[PrikazniNaziv] = @PrikazniNaziv
					,[Izvjestaj] = @Izvjestaj
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportiServer_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportiServer_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportiServer_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblReportiServer table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportiServer_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblReportiServer] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportiServer_GetByIDReport procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportiServer_GetByIDReport') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportiServer_GetByIDReport
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReportiServer table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportiServer_GetByIDReport
(

	@IDReport int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[Izvjestaj]
				FROM
					[dbo].[tblReportiServer]
				WHERE
					[IDReport] = @IDReport
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportiServer_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportiServer_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportiServer_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblReportiServer table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportiServer_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDReport],
					[PrikazniNaziv],
					[Izvjestaj]
				FROM
					[dbo].[tblReportiServer]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblReportiServer_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblReportiServer_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblReportiServer_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblReportiServer table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblReportiServer_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDReport int   = null ,

	@PrikazniNaziv nvarchar (200)  = null ,

	@Izvjestaj varbinary (MAX)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDReport]
	, [PrikazniNaziv]
	, [Izvjestaj]
    FROM
	[dbo].[tblReportiServer]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDReport] = @IDReport OR @IDReport is null)
	AND ([PrikazniNaziv] = @PrikazniNaziv OR @PrikazniNaziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDReport]
	, [PrikazniNaziv]
	, [Izvjestaj]
    FROM
	[dbo].[tblReportiServer]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDReport] = @IDReport AND @IDReport is not null)
	OR ([PrikazniNaziv] = @PrikazniNaziv AND @PrikazniNaziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblRazdobljeStopa_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblRazdobljeStopa_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblRazdobljeStopa_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblRazdobljeStopa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblRazdobljeStopa_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[Stopa]
				FROM
					[fin].[tblRazdobljeStopa]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblRazdobljeStopa_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblRazdobljeStopa_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblRazdobljeStopa_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblRazdobljeStopa table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblRazdobljeStopa_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [Stopa]'
				SET @SQL = @SQL + ' FROM [fin].[tblRazdobljeStopa]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [Stopa]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblRazdobljeStopa]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblRazdobljeStopa_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblRazdobljeStopa_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblRazdobljeStopa_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblRazdobljeStopa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblRazdobljeStopa_Insert
(

	@ID int    OUTPUT,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@Stopa float   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblRazdobljeStopa]
					(
					[DatumOd]
					,[DatumDo]
					,[Stopa]
					)
				VALUES
					(
					@DatumOd
					,@DatumDo
					,@Stopa
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblRazdobljeStopa_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblRazdobljeStopa_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblRazdobljeStopa_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblRazdobljeStopa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblRazdobljeStopa_Update
(

	@ID int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@Stopa float   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblRazdobljeStopa]
				SET
					[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[Stopa] = @Stopa
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblRazdobljeStopa_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblRazdobljeStopa_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblRazdobljeStopa_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblRazdobljeStopa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblRazdobljeStopa_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblRazdobljeStopa] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblRazdobljeStopa_GetByDatumOd procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblRazdobljeStopa_GetByDatumOd') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblRazdobljeStopa_GetByDatumOd
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRazdobljeStopa table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblRazdobljeStopa_GetByDatumOd
(

	@DatumOd datetime   
)
AS


				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[Stopa]
				FROM
					[fin].[tblRazdobljeStopa]
				WHERE
					[DatumOd] = @DatumOd
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblRazdobljeStopa_GetByDatumDo procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblRazdobljeStopa_GetByDatumDo') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblRazdobljeStopa_GetByDatumDo
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRazdobljeStopa table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblRazdobljeStopa_GetByDatumDo
(

	@DatumDo datetime   
)
AS


				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[Stopa]
				FROM
					[fin].[tblRazdobljeStopa]
				WHERE
					[DatumDo] = @DatumDo
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblRazdobljeStopa_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblRazdobljeStopa_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblRazdobljeStopa_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRazdobljeStopa table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblRazdobljeStopa_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[Stopa]
				FROM
					[fin].[tblRazdobljeStopa]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblRazdobljeStopa_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblRazdobljeStopa_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblRazdobljeStopa_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblRazdobljeStopa table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblRazdobljeStopa_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@Stopa float   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [DatumOd]
	, [DatumDo]
	, [Stopa]
    FROM
	[fin].[tblRazdobljeStopa]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([Stopa] = @Stopa OR @Stopa is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [DatumOd]
	, [DatumDo]
	, [Stopa]
    FROM
	[fin].[tblRazdobljeStopa]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([Stopa] = @Stopa AND @Stopa is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRazdoblje_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRazdoblje_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRazdoblje_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblRazdoblje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRazdoblje_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[DateCreated],
					[DateModified],
					[IDUserCreated],
					[IDUserModified],
					[Koristiti]
				FROM
					[dbo].[tblRazdoblje]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRazdoblje_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRazdoblje_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRazdoblje_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblRazdoblje table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRazdoblje_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [DateCreated]'
				SET @SQL = @SQL + ', [DateModified]'
				SET @SQL = @SQL + ', [IDUserCreated]'
				SET @SQL = @SQL + ', [IDUserModified]'
				SET @SQL = @SQL + ', [Koristiti]'
				SET @SQL = @SQL + ' FROM [dbo].[tblRazdoblje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [DateCreated],'
				SET @SQL = @SQL + ' [DateModified],'
				SET @SQL = @SQL + ' [IDUserCreated],'
				SET @SQL = @SQL + ' [IDUserModified],'
				SET @SQL = @SQL + ' [Koristiti]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblRazdoblje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRazdoblje_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRazdoblje_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRazdoblje_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblRazdoblje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRazdoblje_Insert
(

	@ID int    OUTPUT,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@Koristiti int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblRazdoblje]
					(
					[DatumOd]
					,[DatumDo]
					,[DateCreated]
					,[DateModified]
					,[IDUserCreated]
					,[IDUserModified]
					,[Koristiti]
					)
				VALUES
					(
					@DatumOd
					,@DatumDo
					,@DateCreated
					,@DateModified
					,@IDUserCreated
					,@IDUserModified
					,@Koristiti
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRazdoblje_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRazdoblje_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRazdoblje_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblRazdoblje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRazdoblje_Update
(

	@ID int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@Koristiti int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblRazdoblje]
				SET
					[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[DateCreated] = @DateCreated
					,[DateModified] = @DateModified
					,[IDUserCreated] = @IDUserCreated
					,[IDUserModified] = @IDUserModified
					,[Koristiti] = @Koristiti
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRazdoblje_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRazdoblje_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRazdoblje_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblRazdoblje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRazdoblje_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblRazdoblje] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRazdoblje_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRazdoblje_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRazdoblje_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblRazdoblje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRazdoblje_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[DateCreated],
					[DateModified],
					[IDUserCreated],
					[IDUserModified],
					[Koristiti]
				FROM
					[dbo].[tblRazdoblje]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblRazdoblje_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblRazdoblje_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblRazdoblje_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblRazdoblje table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblRazdoblje_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@DateCreated datetime   = null ,

	@DateModified datetime   = null ,

	@IDUserCreated int   = null ,

	@IDUserModified int   = null ,

	@Koristiti int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [DatumOd]
	, [DatumDo]
	, [DateCreated]
	, [DateModified]
	, [IDUserCreated]
	, [IDUserModified]
	, [Koristiti]
    FROM
	[dbo].[tblRazdoblje]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([DateCreated] = @DateCreated OR @DateCreated is null)
	AND ([DateModified] = @DateModified OR @DateModified is null)
	AND ([IDUserCreated] = @IDUserCreated OR @IDUserCreated is null)
	AND ([IDUserModified] = @IDUserModified OR @IDUserModified is null)
	AND ([Koristiti] = @Koristiti OR @Koristiti is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [DatumOd]
	, [DatumDo]
	, [DateCreated]
	, [DateModified]
	, [IDUserCreated]
	, [IDUserModified]
	, [Koristiti]
    FROM
	[dbo].[tblRazdoblje]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([DateCreated] = @DateCreated AND @DateCreated is not null)
	OR ([DateModified] = @DateModified AND @DateModified is not null)
	OR ([IDUserCreated] = @IDUserCreated AND @IDUserCreated is not null)
	OR ([IDUserModified] = @IDUserModified AND @IDUserModified is not null)
	OR ([Koristiti] = @Koristiti AND @Koristiti is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunVirman_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunVirman_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunVirman_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracunVirman table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunVirman_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDObracun],
					[IDVirman]
				FROM
					[pla].[tblObracunVirman]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunVirman_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunVirman_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunVirman_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracunVirman table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunVirman_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDObracun]'
				SET @SQL = @SQL + ', [IDVirman]'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunVirman]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDObracun],'
				SET @SQL = @SQL + ' [IDVirman]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunVirman]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunVirman_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunVirman_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunVirman_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracunVirman table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunVirman_Insert
(

	@ID int    OUTPUT,

	@IDObracun int   ,

	@IDVirman int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblObracunVirman]
					(
					[IDObracun]
					,[IDVirman]
					)
				VALUES
					(
					@IDObracun
					,@IDVirman
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunVirman_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunVirman_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunVirman_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracunVirman table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunVirman_Update
(

	@ID int   ,

	@IDObracun int   ,

	@IDVirman int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblObracunVirman]
				SET
					[IDObracun] = @IDObracun
					,[IDVirman] = @IDVirman
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunVirman_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunVirman_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunVirman_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracunVirman table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunVirman_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblObracunVirman] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunVirman_GetByIDObracun procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunVirman_GetByIDObracun') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunVirman_GetByIDObracun
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunVirman table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunVirman_GetByIDObracun
(

	@IDObracun int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDObracun],
					[IDVirman]
				FROM
					[pla].[tblObracunVirman]
				WHERE
					[IDObracun] = @IDObracun
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunVirman_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunVirman_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunVirman_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunVirman table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunVirman_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDObracun],
					[IDVirman]
				FROM
					[pla].[tblObracunVirman]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunVirman_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunVirman_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunVirman_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracunVirman table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunVirman_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDObracun int   = null ,

	@IDVirman int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDObracun]
	, [IDVirman]
    FROM
	[pla].[tblObracunVirman]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDObracun] = @IDObracun OR @IDObracun is null)
	AND ([IDVirman] = @IDVirman OR @IDVirman is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDObracun]
	, [IDVirman]
    FROM
	[pla].[tblObracunVirman]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDObracun] = @IDObracun AND @IDObracun is not null)
	OR ([IDVirman] = @IDVirman AND @IDVirman is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunRSM_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunRSM_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunRSM_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracunRSM table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunRSM_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[RSMFile],
					[RSMSHA]
				FROM
					[pla].[tblObracunRSM]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunRSM_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunRSM_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunRSM_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracunRSM table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunRSM_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [RSMFile]'
				SET @SQL = @SQL + ', [RSMSHA]'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunRSM]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [RSMFile],'
				SET @SQL = @SQL + ' [RSMSHA]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunRSM]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunRSM_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunRSM_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunRSM_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracunRSM table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunRSM_Insert
(

	@ID int   ,

	@RSMFile varbinary (MAX)  ,

	@RSMSHA nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblObracunRSM]
					(
					[ID]
					,[RSMFile]
					,[RSMSHA]
					)
				VALUES
					(
					@ID
					,@RSMFile
					,@RSMSHA
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunRSM_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunRSM_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunRSM_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracunRSM table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunRSM_Update
(

	@ID int   ,

	@OriginalID int   ,

	@RSMFile varbinary (MAX)  ,

	@RSMSHA nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblObracunRSM]
				SET
					[ID] = @ID
					,[RSMFile] = @RSMFile
					,[RSMSHA] = @RSMSHA
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunRSM_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunRSM_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunRSM_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracunRSM table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunRSM_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblObracunRSM] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunRSM_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunRSM_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunRSM_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunRSM table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunRSM_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[RSMFile],
					[RSMSHA]
				FROM
					[pla].[tblObracunRSM]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunRSM_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunRSM_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunRSM_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracunRSM table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunRSM_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@RSMFile varbinary (MAX)  = null ,

	@RSMSHA nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [RSMFile]
	, [RSMSHA]
    FROM
	[pla].[tblObracunRSM]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([RSMSHA] = @RSMSHA OR @RSMSHA is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [RSMFile]
	, [RSMSHA]
    FROM
	[pla].[tblObracunRSM]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([RSMSHA] = @RSMSHA AND @RSMSHA is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDokument table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDokument table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDDokumentTip]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [Napomena2]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [IDOrganizacijaOd]'
				SET @SQL = @SQL + ', [IDOrganizacijaPrema]'
				SET @SQL = @SQL + ', [IDNacinTransporta]'
				SET @SQL = @SQL + ', [IDNacinPlacanja]'
				SET @SQL = @SQL + ', [IDUserCreated]'
				SET @SQL = @SQL + ', [IDUserModified]'
				SET @SQL = @SQL + ', [DateCreated]'
				SET @SQL = @SQL + ', [DateModified]'
				SET @SQL = @SQL + ', [IDUserIzdao]'
				SET @SQL = @SQL + ', [IDUserPrimio]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [NabavnaVrijednost]'
				SET @SQL = @SQL + ', [PorezNabavneVrijednosti]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ', [IDValute]'
				SET @SQL = @SQL + ', [VezaDokumenta]'
				SET @SQL = @SQL + ', [IDOrganizacijaZiroRacun]'
				SET @SQL = @SQL + ', [DokumentMijenjaCijenu]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokument]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDDokumentTip],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [Napomena2],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [IDOrganizacijaOd],'
				SET @SQL = @SQL + ' [IDOrganizacijaPrema],'
				SET @SQL = @SQL + ' [IDNacinTransporta],'
				SET @SQL = @SQL + ' [IDNacinPlacanja],'
				SET @SQL = @SQL + ' [IDUserCreated],'
				SET @SQL = @SQL + ' [IDUserModified],'
				SET @SQL = @SQL + ' [DateCreated],'
				SET @SQL = @SQL + ' [DateModified],'
				SET @SQL = @SQL + ' [IDUserIzdao],'
				SET @SQL = @SQL + ' [IDUserPrimio],'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [NabavnaVrijednost],'
				SET @SQL = @SQL + ' [PorezNabavneVrijednosti],'
				SET @SQL = @SQL + ' [IDStatus],'
				SET @SQL = @SQL + ' [IDValute],'
				SET @SQL = @SQL + ' [VezaDokumenta],'
				SET @SQL = @SQL + ' [IDOrganizacijaZiroRacun],'
				SET @SQL = @SQL + ' [DokumentMijenjaCijenu]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokument]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDokument table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_Insert
(

	@ID int    OUTPUT,

	@IDDokumentTip int   ,

	@Oznaka nvarchar (50)  ,

	@Datum datetime   ,

	@DatumDo datetime   ,

	@Napomena nvarchar (300)  ,

	@Napomena2 nvarchar (300)  ,

	@IDKlijent int   ,

	@IDOrganizacijaOd int   ,

	@IDOrganizacijaPrema int   ,

	@IDNacinTransporta int   ,

	@IDNacinPlacanja int   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@IDUserIzdao int   ,

	@IDUserPrimio int   ,

	@RedBr int   ,

	@NabavnaVrijednost money   ,

	@PorezNabavneVrijednosti real   ,

	@IDStatus int   ,

	@IDValute int   ,

	@VezaDokumenta nvarchar (50)  ,

	@IDOrganizacijaZiroRacun int   ,

	@DokumentMijenjaCijenu int    OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDokument]
					(
					[IDDokumentTip]
					,[Oznaka]
					,[Datum]
					,[DatumDo]
					,[Napomena]
					,[Napomena2]
					,[IDKlijent]
					,[IDOrganizacijaOd]
					,[IDOrganizacijaPrema]
					,[IDNacinTransporta]
					,[IDNacinPlacanja]
					,[IDUserCreated]
					,[IDUserModified]
					,[DateCreated]
					,[DateModified]
					,[IDUserIzdao]
					,[IDUserPrimio]
					,[RedBr]
					,[NabavnaVrijednost]
					,[PorezNabavneVrijednosti]
					,[IDStatus]
					,[IDValute]
					,[VezaDokumenta]
					,[IDOrganizacijaZiroRacun]
					)
				VALUES
					(
					@IDDokumentTip
					,@Oznaka
					,@Datum
					,@DatumDo
					,@Napomena
					,@Napomena2
					,@IDKlijent
					,@IDOrganizacijaOd
					,@IDOrganizacijaPrema
					,@IDNacinTransporta
					,@IDNacinPlacanja
					,@IDUserCreated
					,@IDUserModified
					,@DateCreated
					,@DateModified
					,@IDUserIzdao
					,@IDUserPrimio
					,@RedBr
					,@NabavnaVrijednost
					,@PorezNabavneVrijednosti
					,@IDStatus
					,@IDValute
					,@VezaDokumenta
					,@IDOrganizacijaZiroRacun
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
				-- Select computed columns into output parameters
				SELECT
 @DokumentMijenjaCijenu = [DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
[ID] = @ID 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDokument table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_Update
(

	@ID int   ,

	@IDDokumentTip int   ,

	@Oznaka nvarchar (50)  ,

	@Datum datetime   ,

	@DatumDo datetime   ,

	@Napomena nvarchar (300)  ,

	@Napomena2 nvarchar (300)  ,

	@IDKlijent int   ,

	@IDOrganizacijaOd int   ,

	@IDOrganizacijaPrema int   ,

	@IDNacinTransporta int   ,

	@IDNacinPlacanja int   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@IDUserIzdao int   ,

	@IDUserPrimio int   ,

	@RedBr int   ,

	@NabavnaVrijednost money   ,

	@PorezNabavneVrijednosti real   ,

	@IDStatus int   ,

	@IDValute int   ,

	@VezaDokumenta nvarchar (50)  ,

	@IDOrganizacijaZiroRacun int   ,

	@DokumentMijenjaCijenu int    OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDokument]
				SET
					[IDDokumentTip] = @IDDokumentTip
					,[Oznaka] = @Oznaka
					,[Datum] = @Datum
					,[DatumDo] = @DatumDo
					,[Napomena] = @Napomena
					,[Napomena2] = @Napomena2
					,[IDKlijent] = @IDKlijent
					,[IDOrganizacijaOd] = @IDOrganizacijaOd
					,[IDOrganizacijaPrema] = @IDOrganizacijaPrema
					,[IDNacinTransporta] = @IDNacinTransporta
					,[IDNacinPlacanja] = @IDNacinPlacanja
					,[IDUserCreated] = @IDUserCreated
					,[IDUserModified] = @IDUserModified
					,[DateCreated] = @DateCreated
					,[DateModified] = @DateModified
					,[IDUserIzdao] = @IDUserIzdao
					,[IDUserPrimio] = @IDUserPrimio
					,[RedBr] = @RedBr
					,[NabavnaVrijednost] = @NabavnaVrijednost
					,[PorezNabavneVrijednosti] = @PorezNabavneVrijednosti
					,[IDStatus] = @IDStatus
					,[IDValute] = @IDValute
					,[VezaDokumenta] = @VezaDokumenta
					,[IDOrganizacijaZiroRacun] = @IDOrganizacijaZiroRacun
				WHERE
[ID] = @ID 
				
				
				-- Select computed columns into output parameters
				SELECT
 @DokumentMijenjaCijenu = [DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
[ID] = @ID 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDokument table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDokument] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDUserPrimio procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDUserPrimio') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDUserPrimio
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDUserPrimio
(

	@IDUserPrimio int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDUserPrimio] = @IDUserPrimio
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDUserIzdao procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDUserIzdao') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDUserIzdao
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDUserIzdao
(

	@IDUserIzdao int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDUserIzdao] = @IDUserIzdao
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDDokumentTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDDokumentTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDDokumentTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDDokumentTip
(

	@IDDokumentTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDDokumentTip] = @IDDokumentTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDKlijent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDKlijent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDKlijent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDKlijent
(

	@IDKlijent int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDKlijent] = @IDKlijent
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDNacinTransporta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDNacinTransporta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDNacinTransporta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDNacinTransporta
(

	@IDNacinTransporta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDNacinTransporta] = @IDNacinTransporta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDNacinPlacanja procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDNacinPlacanja') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDNacinPlacanja
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDNacinPlacanja
(

	@IDNacinPlacanja int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDNacinPlacanja] = @IDNacinPlacanja
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDOrganizacijaOd procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDOrganizacijaOd') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDOrganizacijaOd
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDOrganizacijaOd
(

	@IDOrganizacijaOd int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDOrganizacijaOd] = @IDOrganizacijaOd
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDOrganizacijaPrema procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDOrganizacijaPrema') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDOrganizacijaPrema
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDOrganizacijaPrema
(

	@IDOrganizacijaPrema int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDOrganizacijaPrema] = @IDOrganizacijaPrema
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDOrganizacijaZiroRacun procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDOrganizacijaZiroRacun') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDOrganizacijaZiroRacun
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDOrganizacijaZiroRacun
(

	@IDOrganizacijaZiroRacun int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDOrganizacijaZiroRacun] = @IDOrganizacijaZiroRacun
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDValute procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDValute') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDValute
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDValute
(

	@IDValute int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDValute] = @IDValute
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDStatusDatumIDDokumentTipIDDateModified procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDStatusDatumIDDokumentTipIDDateModified') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDStatusDatumIDDokumentTipIDDateModified
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDStatusDatumIDDokumentTipIDDateModified
(

	@IDStatus int   ,

	@Datum datetime   ,

	@IDDokumentTip int   ,

	@ID int   ,

	@DateModified datetime   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDStatus] = @IDStatus
					AND [Datum] = @Datum
					AND [IDDokumentTip] = @IDDokumentTip
					AND [ID] = @ID
					AND [DateModified] = @DateModified
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByDokumentMijenjaCijenuDatumDateModifiedIDIDStatusIDDokumentTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByDokumentMijenjaCijenuDatumDateModifiedIDIDStatusIDDokumentTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByDokumentMijenjaCijenuDatumDateModifiedIDIDStatusIDDokumentTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByDokumentMijenjaCijenuDatumDateModifiedIDIDStatusIDDokumentTip
(

	@DokumentMijenjaCijenu int   ,

	@Datum datetime   ,

	@DateModified datetime   ,

	@ID int   ,

	@IDStatus int   ,

	@IDDokumentTip int   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[DokumentMijenjaCijenu] = @DokumentMijenjaCijenu
					AND [Datum] = @Datum
					AND [DateModified] = @DateModified
					AND [ID] = @ID
					AND [IDStatus] = @IDStatus
					AND [IDDokumentTip] = @IDDokumentTip
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByDatumIDDokumentTipIDStatusIDDateModified procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByDatumIDDokumentTipIDStatusIDDateModified') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByDatumIDDokumentTipIDStatusIDDateModified
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByDatumIDDokumentTipIDStatusIDDateModified
(

	@Datum datetime   ,

	@IDDokumentTip int   ,

	@IDStatus int   ,

	@ID int   ,

	@DateModified datetime   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[Datum] = @Datum
					AND [IDDokumentTip] = @IDDokumentTip
					AND [IDStatus] = @IDStatus
					AND [ID] = @ID
					AND [DateModified] = @DateModified
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDIDDokumentTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDIDDokumentTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDIDDokumentTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDIDDokumentTip
(

	@ID int   ,

	@IDDokumentTip int   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[ID] = @ID
					AND [IDDokumentTip] = @IDDokumentTip
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDDokumentTipIDIDStatus procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDDokumentTipIDIDStatus') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDDokumentTipIDIDStatus
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDDokumentTipIDIDStatus
(

	@IDDokumentTip int   ,

	@ID int   ,

	@IDStatus int   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDDokumentTip] = @IDDokumentTip
					AND [ID] = @ID
					AND [IDStatus] = @IDStatus
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDDokumentTipIDStatusIDDatum procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDDokumentTipIDStatusIDDatum') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDDokumentTipIDStatusIDDatum
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDDokumentTipIDStatusIDDatum
(

	@IDDokumentTip int   ,

	@IDStatus int   ,

	@ID int   ,

	@Datum datetime   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDDokumentTip] = @IDDokumentTip
					AND [IDStatus] = @IDStatus
					AND [ID] = @ID
					AND [Datum] = @Datum
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDStatusIDIDDokumentTipDatum procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDStatusIDIDDokumentTipDatum') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDStatusIDIDDokumentTipDatum
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDStatusIDIDDokumentTipDatum
(

	@IDStatus int   ,

	@ID int   ,

	@IDDokumentTip int   ,

	@Datum datetime   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDStatus] = @IDStatus
					AND [ID] = @ID
					AND [IDDokumentTip] = @IDDokumentTip
					AND [Datum] = @Datum
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDDokumentTipIDStatusDatumIDDateModified procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDDokumentTipIDStatusDatumIDDateModified') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDDokumentTipIDStatusDatumIDDateModified
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDDokumentTipIDStatusDatumIDDateModified
(

	@IDDokumentTip int   ,

	@IDStatus int   ,

	@Datum datetime   ,

	@ID int   ,

	@DateModified datetime   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDDokumentTip] = @IDDokumentTip
					AND [IDStatus] = @IDStatus
					AND [Datum] = @Datum
					AND [ID] = @ID
					AND [DateModified] = @DateModified
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDDokumentTipIDStatusDatumID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDDokumentTipIDStatusDatumID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDDokumentTipIDStatusDatumID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDDokumentTipIDStatusDatumID
(

	@IDDokumentTip int   ,

	@IDStatus int   ,

	@Datum datetime   ,

	@ID int   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDDokumentTip] = @IDDokumentTip
					AND [IDStatus] = @IDStatus
					AND [Datum] = @Datum
					AND [ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDStatus procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDStatus') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDStatus
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDStatus
(

	@IDStatus int   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[IDStatus] = @IDStatus
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokument table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDDokumentTip],
					[Oznaka],
					[Datum],
					[DatumDo],
					[Napomena],
					[Napomena2],
					[IDKlijent],
					[IDOrganizacijaOd],
					[IDOrganizacijaPrema],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified],
					[IDUserIzdao],
					[IDUserPrimio],
					[RedBr],
					[NabavnaVrijednost],
					[PorezNabavneVrijednosti],
					[IDStatus],
					[IDValute],
					[VezaDokumenta],
					[IDOrganizacijaZiroRacun],
					[DokumentMijenjaCijenu]
				FROM
					[dbo].[tblDokument]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDParentFromRadniNalogVeza procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDParentFromRadniNalogVeza') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDParentFromRadniNalogVeza
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records through a junction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDParentFromRadniNalogVeza
(

	@IDParent int   
)
AS


SELECT dbo.[tblDokument].[ID]
       ,dbo.[tblDokument].[IDDokumentTip]
       ,dbo.[tblDokument].[Oznaka]
       ,dbo.[tblDokument].[Datum]
       ,dbo.[tblDokument].[DatumDo]
       ,dbo.[tblDokument].[Napomena]
       ,dbo.[tblDokument].[Napomena2]
       ,dbo.[tblDokument].[IDKlijent]
       ,dbo.[tblDokument].[IDOrganizacijaOd]
       ,dbo.[tblDokument].[IDOrganizacijaPrema]
       ,dbo.[tblDokument].[IDNacinTransporta]
       ,dbo.[tblDokument].[IDNacinPlacanja]
       ,dbo.[tblDokument].[IDUserCreated]
       ,dbo.[tblDokument].[IDUserModified]
       ,dbo.[tblDokument].[DateCreated]
       ,dbo.[tblDokument].[DateModified]
       ,dbo.[tblDokument].[IDUserIzdao]
       ,dbo.[tblDokument].[IDUserPrimio]
       ,dbo.[tblDokument].[RedBr]
       ,dbo.[tblDokument].[NabavnaVrijednost]
       ,dbo.[tblDokument].[PorezNabavneVrijednosti]
       ,dbo.[tblDokument].[IDStatus]
       ,dbo.[tblDokument].[IDValute]
       ,dbo.[tblDokument].[VezaDokumenta]
       ,dbo.[tblDokument].[IDOrganizacijaZiroRacun]
       ,dbo.[tblDokument].[DokumentMijenjaCijenu]
  FROM dbo.[tblDokument]
 WHERE EXISTS (SELECT 1
                 FROM dbo.[tblRadniNalogVeza] 
                WHERE dbo.[tblRadniNalogVeza].[IDParent] = @IDParent
                  AND dbo.[tblRadniNalogVeza].[IDChild] = dbo.[tblDokument].[ID]
                  )
				Select @@ROWCOUNT			
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDChildFromRadniNalogVeza procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDChildFromRadniNalogVeza') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDChildFromRadniNalogVeza
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records through a junction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDChildFromRadniNalogVeza
(

	@IDChild int   
)
AS


SELECT dbo.[tblDokument].[ID]
       ,dbo.[tblDokument].[IDDokumentTip]
       ,dbo.[tblDokument].[Oznaka]
       ,dbo.[tblDokument].[Datum]
       ,dbo.[tblDokument].[DatumDo]
       ,dbo.[tblDokument].[Napomena]
       ,dbo.[tblDokument].[Napomena2]
       ,dbo.[tblDokument].[IDKlijent]
       ,dbo.[tblDokument].[IDOrganizacijaOd]
       ,dbo.[tblDokument].[IDOrganizacijaPrema]
       ,dbo.[tblDokument].[IDNacinTransporta]
       ,dbo.[tblDokument].[IDNacinPlacanja]
       ,dbo.[tblDokument].[IDUserCreated]
       ,dbo.[tblDokument].[IDUserModified]
       ,dbo.[tblDokument].[DateCreated]
       ,dbo.[tblDokument].[DateModified]
       ,dbo.[tblDokument].[IDUserIzdao]
       ,dbo.[tblDokument].[IDUserPrimio]
       ,dbo.[tblDokument].[RedBr]
       ,dbo.[tblDokument].[NabavnaVrijednost]
       ,dbo.[tblDokument].[PorezNabavneVrijednosti]
       ,dbo.[tblDokument].[IDStatus]
       ,dbo.[tblDokument].[IDValute]
       ,dbo.[tblDokument].[VezaDokumenta]
       ,dbo.[tblDokument].[IDOrganizacijaZiroRacun]
       ,dbo.[tblDokument].[DokumentMijenjaCijenu]
  FROM dbo.[tblDokument]
 WHERE EXISTS (SELECT 1
                 FROM dbo.[tblRadniNalogVeza] 
                WHERE dbo.[tblRadniNalogVeza].[IDChild] = @IDChild
                  AND dbo.[tblRadniNalogVeza].[IDParent] = dbo.[tblDokument].[ID]
                  )
				Select @@ROWCOUNT			
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDParentFromVeza procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDParentFromVeza') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDParentFromVeza
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records through a junction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDParentFromVeza
(

	@IDParent int   
)
AS


SELECT dbo.[tblDokument].[ID]
       ,dbo.[tblDokument].[IDDokumentTip]
       ,dbo.[tblDokument].[Oznaka]
       ,dbo.[tblDokument].[Datum]
       ,dbo.[tblDokument].[DatumDo]
       ,dbo.[tblDokument].[Napomena]
       ,dbo.[tblDokument].[Napomena2]
       ,dbo.[tblDokument].[IDKlijent]
       ,dbo.[tblDokument].[IDOrganizacijaOd]
       ,dbo.[tblDokument].[IDOrganizacijaPrema]
       ,dbo.[tblDokument].[IDNacinTransporta]
       ,dbo.[tblDokument].[IDNacinPlacanja]
       ,dbo.[tblDokument].[IDUserCreated]
       ,dbo.[tblDokument].[IDUserModified]
       ,dbo.[tblDokument].[DateCreated]
       ,dbo.[tblDokument].[DateModified]
       ,dbo.[tblDokument].[IDUserIzdao]
       ,dbo.[tblDokument].[IDUserPrimio]
       ,dbo.[tblDokument].[RedBr]
       ,dbo.[tblDokument].[NabavnaVrijednost]
       ,dbo.[tblDokument].[PorezNabavneVrijednosti]
       ,dbo.[tblDokument].[IDStatus]
       ,dbo.[tblDokument].[IDValute]
       ,dbo.[tblDokument].[VezaDokumenta]
       ,dbo.[tblDokument].[IDOrganizacijaZiroRacun]
       ,dbo.[tblDokument].[DokumentMijenjaCijenu]
  FROM dbo.[tblDokument]
 WHERE EXISTS (SELECT 1
                 FROM dbo.[tblVeza] 
                WHERE dbo.[tblVeza].[IDParent] = @IDParent
                  AND dbo.[tblVeza].[IDChild] = dbo.[tblDokument].[ID]
                  )
				Select @@ROWCOUNT			
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_GetByIDChildFromVeza procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_GetByIDChildFromVeza') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_GetByIDChildFromVeza
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records through a junction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_GetByIDChildFromVeza
(

	@IDChild int   
)
AS


SELECT dbo.[tblDokument].[ID]
       ,dbo.[tblDokument].[IDDokumentTip]
       ,dbo.[tblDokument].[Oznaka]
       ,dbo.[tblDokument].[Datum]
       ,dbo.[tblDokument].[DatumDo]
       ,dbo.[tblDokument].[Napomena]
       ,dbo.[tblDokument].[Napomena2]
       ,dbo.[tblDokument].[IDKlijent]
       ,dbo.[tblDokument].[IDOrganizacijaOd]
       ,dbo.[tblDokument].[IDOrganizacijaPrema]
       ,dbo.[tblDokument].[IDNacinTransporta]
       ,dbo.[tblDokument].[IDNacinPlacanja]
       ,dbo.[tblDokument].[IDUserCreated]
       ,dbo.[tblDokument].[IDUserModified]
       ,dbo.[tblDokument].[DateCreated]
       ,dbo.[tblDokument].[DateModified]
       ,dbo.[tblDokument].[IDUserIzdao]
       ,dbo.[tblDokument].[IDUserPrimio]
       ,dbo.[tblDokument].[RedBr]
       ,dbo.[tblDokument].[NabavnaVrijednost]
       ,dbo.[tblDokument].[PorezNabavneVrijednosti]
       ,dbo.[tblDokument].[IDStatus]
       ,dbo.[tblDokument].[IDValute]
       ,dbo.[tblDokument].[VezaDokumenta]
       ,dbo.[tblDokument].[IDOrganizacijaZiroRacun]
       ,dbo.[tblDokument].[DokumentMijenjaCijenu]
  FROM dbo.[tblDokument]
 WHERE EXISTS (SELECT 1
                 FROM dbo.[tblVeza] 
                WHERE dbo.[tblVeza].[IDChild] = @IDChild
                  AND dbo.[tblVeza].[IDParent] = dbo.[tblDokument].[ID]
                  )
				Select @@ROWCOUNT			
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokument_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokument_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokument_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDokument table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokument_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDDokumentTip int   = null ,

	@Oznaka nvarchar (50)  = null ,

	@Datum datetime   = null ,

	@DatumDo datetime   = null ,

	@Napomena nvarchar (300)  = null ,

	@Napomena2 nvarchar (300)  = null ,

	@IDKlijent int   = null ,

	@IDOrganizacijaOd int   = null ,

	@IDOrganizacijaPrema int   = null ,

	@IDNacinTransporta int   = null ,

	@IDNacinPlacanja int   = null ,

	@IDUserCreated int   = null ,

	@IDUserModified int   = null ,

	@DateCreated datetime   = null ,

	@DateModified datetime   = null ,

	@IDUserIzdao int   = null ,

	@IDUserPrimio int   = null ,

	@RedBr int   = null ,

	@NabavnaVrijednost money   = null ,

	@PorezNabavneVrijednosti real   = null ,

	@IDStatus int   = null ,

	@IDValute int   = null ,

	@VezaDokumenta nvarchar (50)  = null ,

	@IDOrganizacijaZiroRacun int   = null ,

	@DokumentMijenjaCijenu int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDDokumentTip]
	, [Oznaka]
	, [Datum]
	, [DatumDo]
	, [Napomena]
	, [Napomena2]
	, [IDKlijent]
	, [IDOrganizacijaOd]
	, [IDOrganizacijaPrema]
	, [IDNacinTransporta]
	, [IDNacinPlacanja]
	, [IDUserCreated]
	, [IDUserModified]
	, [DateCreated]
	, [DateModified]
	, [IDUserIzdao]
	, [IDUserPrimio]
	, [RedBr]
	, [NabavnaVrijednost]
	, [PorezNabavneVrijednosti]
	, [IDStatus]
	, [IDValute]
	, [VezaDokumenta]
	, [IDOrganizacijaZiroRacun]
	, [DokumentMijenjaCijenu]
    FROM
	[dbo].[tblDokument]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDDokumentTip] = @IDDokumentTip OR @IDDokumentTip is null)
	AND ([Oznaka] = @Oznaka OR @Oznaka is null)
	AND ([Datum] = @Datum OR @Datum is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([Napomena2] = @Napomena2 OR @Napomena2 is null)
	AND ([IDKlijent] = @IDKlijent OR @IDKlijent is null)
	AND ([IDOrganizacijaOd] = @IDOrganizacijaOd OR @IDOrganizacijaOd is null)
	AND ([IDOrganizacijaPrema] = @IDOrganizacijaPrema OR @IDOrganizacijaPrema is null)
	AND ([IDNacinTransporta] = @IDNacinTransporta OR @IDNacinTransporta is null)
	AND ([IDNacinPlacanja] = @IDNacinPlacanja OR @IDNacinPlacanja is null)
	AND ([IDUserCreated] = @IDUserCreated OR @IDUserCreated is null)
	AND ([IDUserModified] = @IDUserModified OR @IDUserModified is null)
	AND ([DateCreated] = @DateCreated OR @DateCreated is null)
	AND ([DateModified] = @DateModified OR @DateModified is null)
	AND ([IDUserIzdao] = @IDUserIzdao OR @IDUserIzdao is null)
	AND ([IDUserPrimio] = @IDUserPrimio OR @IDUserPrimio is null)
	AND ([RedBr] = @RedBr OR @RedBr is null)
	AND ([NabavnaVrijednost] = @NabavnaVrijednost OR @NabavnaVrijednost is null)
	AND ([PorezNabavneVrijednosti] = @PorezNabavneVrijednosti OR @PorezNabavneVrijednosti is null)
	AND ([IDStatus] = @IDStatus OR @IDStatus is null)
	AND ([IDValute] = @IDValute OR @IDValute is null)
	AND ([VezaDokumenta] = @VezaDokumenta OR @VezaDokumenta is null)
	AND ([IDOrganizacijaZiroRacun] = @IDOrganizacijaZiroRacun OR @IDOrganizacijaZiroRacun is null)
	AND ([DokumentMijenjaCijenu] = @DokumentMijenjaCijenu OR @DokumentMijenjaCijenu is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDDokumentTip]
	, [Oznaka]
	, [Datum]
	, [DatumDo]
	, [Napomena]
	, [Napomena2]
	, [IDKlijent]
	, [IDOrganizacijaOd]
	, [IDOrganizacijaPrema]
	, [IDNacinTransporta]
	, [IDNacinPlacanja]
	, [IDUserCreated]
	, [IDUserModified]
	, [DateCreated]
	, [DateModified]
	, [IDUserIzdao]
	, [IDUserPrimio]
	, [RedBr]
	, [NabavnaVrijednost]
	, [PorezNabavneVrijednosti]
	, [IDStatus]
	, [IDValute]
	, [VezaDokumenta]
	, [IDOrganizacijaZiroRacun]
	, [DokumentMijenjaCijenu]
    FROM
	[dbo].[tblDokument]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDDokumentTip] = @IDDokumentTip AND @IDDokumentTip is not null)
	OR ([Oznaka] = @Oznaka AND @Oznaka is not null)
	OR ([Datum] = @Datum AND @Datum is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([Napomena2] = @Napomena2 AND @Napomena2 is not null)
	OR ([IDKlijent] = @IDKlijent AND @IDKlijent is not null)
	OR ([IDOrganizacijaOd] = @IDOrganizacijaOd AND @IDOrganizacijaOd is not null)
	OR ([IDOrganizacijaPrema] = @IDOrganizacijaPrema AND @IDOrganizacijaPrema is not null)
	OR ([IDNacinTransporta] = @IDNacinTransporta AND @IDNacinTransporta is not null)
	OR ([IDNacinPlacanja] = @IDNacinPlacanja AND @IDNacinPlacanja is not null)
	OR ([IDUserCreated] = @IDUserCreated AND @IDUserCreated is not null)
	OR ([IDUserModified] = @IDUserModified AND @IDUserModified is not null)
	OR ([DateCreated] = @DateCreated AND @DateCreated is not null)
	OR ([DateModified] = @DateModified AND @DateModified is not null)
	OR ([IDUserIzdao] = @IDUserIzdao AND @IDUserIzdao is not null)
	OR ([IDUserPrimio] = @IDUserPrimio AND @IDUserPrimio is not null)
	OR ([RedBr] = @RedBr AND @RedBr is not null)
	OR ([NabavnaVrijednost] = @NabavnaVrijednost AND @NabavnaVrijednost is not null)
	OR ([PorezNabavneVrijednosti] = @PorezNabavneVrijednosti AND @PorezNabavneVrijednosti is not null)
	OR ([IDStatus] = @IDStatus AND @IDStatus is not null)
	OR ([IDValute] = @IDValute AND @IDValute is not null)
	OR ([VezaDokumenta] = @VezaDokumenta AND @VezaDokumenta is not null)
	OR ([IDOrganizacijaZiroRacun] = @IDOrganizacijaZiroRacun AND @IDOrganizacijaZiroRacun is not null)
	OR ([DokumentMijenjaCijenu] = @DokumentMijenjaCijenu AND @DokumentMijenjaCijenu is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentPlacanje_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentPlacanje_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentPlacanje_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDokumentPlacanje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentPlacanje_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokument],
					[IDNacinPlacanja],
					[Uplaceno],
					[Datum]
				FROM
					[dbo].[tblDokumentPlacanje]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentPlacanje_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentPlacanje_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentPlacanje_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDokumentPlacanje table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentPlacanje_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDDokument]'
				SET @SQL = @SQL + ', [IDNacinPlacanja]'
				SET @SQL = @SQL + ', [Uplaceno]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentPlacanje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDDokument],'
				SET @SQL = @SQL + ' [IDNacinPlacanja],'
				SET @SQL = @SQL + ' [Uplaceno],'
				SET @SQL = @SQL + ' [Datum]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentPlacanje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentPlacanje_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentPlacanje_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentPlacanje_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDokumentPlacanje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentPlacanje_Insert
(

	@ID int    OUTPUT,

	@IDDokument int   ,

	@IDNacinPlacanja int   ,

	@Uplaceno money   ,

	@Datum datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDokumentPlacanje]
					(
					[IDDokument]
					,[IDNacinPlacanja]
					,[Uplaceno]
					,[Datum]
					)
				VALUES
					(
					@IDDokument
					,@IDNacinPlacanja
					,@Uplaceno
					,@Datum
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentPlacanje_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentPlacanje_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentPlacanje_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDokumentPlacanje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentPlacanje_Update
(

	@ID int   ,

	@IDDokument int   ,

	@IDNacinPlacanja int   ,

	@Uplaceno money   ,

	@Datum datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDokumentPlacanje]
				SET
					[IDDokument] = @IDDokument
					,[IDNacinPlacanja] = @IDNacinPlacanja
					,[Uplaceno] = @Uplaceno
					,[Datum] = @Datum
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentPlacanje_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentPlacanje_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentPlacanje_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDokumentPlacanje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentPlacanje_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDokumentPlacanje] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentPlacanje_GetByIDDokument procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentPlacanje_GetByIDDokument') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentPlacanje_GetByIDDokument
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentPlacanje table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentPlacanje_GetByIDDokument
(

	@IDDokument int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokument],
					[IDNacinPlacanja],
					[Uplaceno],
					[Datum]
				FROM
					[dbo].[tblDokumentPlacanje]
				WHERE
					[IDDokument] = @IDDokument
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentPlacanje_GetByIDNacinPlacanja procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentPlacanje_GetByIDNacinPlacanja') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentPlacanje_GetByIDNacinPlacanja
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentPlacanje table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentPlacanje_GetByIDNacinPlacanja
(

	@IDNacinPlacanja int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokument],
					[IDNacinPlacanja],
					[Uplaceno],
					[Datum]
				FROM
					[dbo].[tblDokumentPlacanje]
				WHERE
					[IDNacinPlacanja] = @IDNacinPlacanja
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentPlacanje_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentPlacanje_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentPlacanje_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentPlacanje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentPlacanje_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDDokument],
					[IDNacinPlacanja],
					[Uplaceno],
					[Datum]
				FROM
					[dbo].[tblDokumentPlacanje]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentPlacanje_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentPlacanje_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentPlacanje_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDokumentPlacanje table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentPlacanje_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDDokument int   = null ,

	@IDNacinPlacanja int   = null ,

	@Uplaceno money   = null ,

	@Datum datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDDokument]
	, [IDNacinPlacanja]
	, [Uplaceno]
	, [Datum]
    FROM
	[dbo].[tblDokumentPlacanje]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDDokument] = @IDDokument OR @IDDokument is null)
	AND ([IDNacinPlacanja] = @IDNacinPlacanja OR @IDNacinPlacanja is null)
	AND ([Uplaceno] = @Uplaceno OR @Uplaceno is null)
	AND ([Datum] = @Datum OR @Datum is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDDokument]
	, [IDNacinPlacanja]
	, [Uplaceno]
	, [Datum]
    FROM
	[dbo].[tblDokumentPlacanje]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDDokument] = @IDDokument AND @IDDokument is not null)
	OR ([IDNacinPlacanja] = @IDNacinPlacanja AND @IDNacinPlacanja is not null)
	OR ([Uplaceno] = @Uplaceno AND @Uplaceno is not null)
	OR ([Datum] = @Datum AND @Datum is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPrimanje_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPrimanje_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPrimanje_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracunOsobaPrimanje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPrimanje_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDObracunOsoba],
					[IDPrimanjeTip],
					[Sati],
					[Postotak],
					[Satnica],
					[DatumOd],
					[DatumDo],
					[Iznos],
					[StazMjeseci1],
					[StazMjeseci2],
					[MIO1],
					[MIO2],
					[BrojDanaInozemstva],
					[StazSPovecanimTrajanjemRegos],
					[IznosSOsobaPlace],
					[DnevnoRadnihSatiSOsobaplaca],
					[OriginalniIznos],
					[DoprinosNaPlace]
				FROM
					[pla].[tblObracunOsobaPrimanje]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPrimanje_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPrimanje_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPrimanje_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracunOsobaPrimanje table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPrimanje_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDObracunOsoba]'
				SET @SQL = @SQL + ', [IDPrimanjeTip]'
				SET @SQL = @SQL + ', [Sati]'
				SET @SQL = @SQL + ', [Postotak]'
				SET @SQL = @SQL + ', [Satnica]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [StazMjeseci1]'
				SET @SQL = @SQL + ', [StazMjeseci2]'
				SET @SQL = @SQL + ', [MIO1]'
				SET @SQL = @SQL + ', [MIO2]'
				SET @SQL = @SQL + ', [BrojDanaInozemstva]'
				SET @SQL = @SQL + ', [StazSPovecanimTrajanjemRegos]'
				SET @SQL = @SQL + ', [IznosSOsobaPlace]'
				SET @SQL = @SQL + ', [DnevnoRadnihSatiSOsobaplaca]'
				SET @SQL = @SQL + ', [OriginalniIznos]'
				SET @SQL = @SQL + ', [DoprinosNaPlace]'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunOsobaPrimanje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDObracunOsoba],'
				SET @SQL = @SQL + ' [IDPrimanjeTip],'
				SET @SQL = @SQL + ' [Sati],'
				SET @SQL = @SQL + ' [Postotak],'
				SET @SQL = @SQL + ' [Satnica],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [StazMjeseci1],'
				SET @SQL = @SQL + ' [StazMjeseci2],'
				SET @SQL = @SQL + ' [MIO1],'
				SET @SQL = @SQL + ' [MIO2],'
				SET @SQL = @SQL + ' [BrojDanaInozemstva],'
				SET @SQL = @SQL + ' [StazSPovecanimTrajanjemRegos],'
				SET @SQL = @SQL + ' [IznosSOsobaPlace],'
				SET @SQL = @SQL + ' [DnevnoRadnihSatiSOsobaplaca],'
				SET @SQL = @SQL + ' [OriginalniIznos],'
				SET @SQL = @SQL + ' [DoprinosNaPlace]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunOsobaPrimanje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPrimanje_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPrimanje_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPrimanje_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracunOsobaPrimanje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPrimanje_Insert
(

	@ID int    OUTPUT,

	@IDObracunOsoba int   ,

	@IDPrimanjeTip int   ,

	@Sati money   ,

	@Postotak money   ,

	@Satnica real   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@Iznos money   ,

	@StazMjeseci1 int   ,

	@StazMjeseci2 int   ,

	@MIO1 bit   ,

	@MIO2 bit   ,

	@BrojDanaInozemstva int   ,

	@StazSPovecanimTrajanjemRegos int   ,

	@IznosSOsobaPlace money   ,

	@DnevnoRadnihSatiSOsobaplaca money   ,

	@OriginalniIznos money   ,

	@DoprinosNaPlace bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblObracunOsobaPrimanje]
					(
					[IDObracunOsoba]
					,[IDPrimanjeTip]
					,[Sati]
					,[Postotak]
					,[Satnica]
					,[DatumOd]
					,[DatumDo]
					,[Iznos]
					,[StazMjeseci1]
					,[StazMjeseci2]
					,[MIO1]
					,[MIO2]
					,[BrojDanaInozemstva]
					,[StazSPovecanimTrajanjemRegos]
					,[IznosSOsobaPlace]
					,[DnevnoRadnihSatiSOsobaplaca]
					,[OriginalniIznos]
					,[DoprinosNaPlace]
					)
				VALUES
					(
					@IDObracunOsoba
					,@IDPrimanjeTip
					,@Sati
					,@Postotak
					,@Satnica
					,@DatumOd
					,@DatumDo
					,@Iznos
					,@StazMjeseci1
					,@StazMjeseci2
					,@MIO1
					,@MIO2
					,@BrojDanaInozemstva
					,@StazSPovecanimTrajanjemRegos
					,@IznosSOsobaPlace
					,@DnevnoRadnihSatiSOsobaplaca
					,@OriginalniIznos
					,@DoprinosNaPlace
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPrimanje_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPrimanje_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPrimanje_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracunOsobaPrimanje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPrimanje_Update
(

	@ID int   ,

	@IDObracunOsoba int   ,

	@IDPrimanjeTip int   ,

	@Sati money   ,

	@Postotak money   ,

	@Satnica real   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@Iznos money   ,

	@StazMjeseci1 int   ,

	@StazMjeseci2 int   ,

	@MIO1 bit   ,

	@MIO2 bit   ,

	@BrojDanaInozemstva int   ,

	@StazSPovecanimTrajanjemRegos int   ,

	@IznosSOsobaPlace money   ,

	@DnevnoRadnihSatiSOsobaplaca money   ,

	@OriginalniIznos money   ,

	@DoprinosNaPlace bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblObracunOsobaPrimanje]
				SET
					[IDObracunOsoba] = @IDObracunOsoba
					,[IDPrimanjeTip] = @IDPrimanjeTip
					,[Sati] = @Sati
					,[Postotak] = @Postotak
					,[Satnica] = @Satnica
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[Iznos] = @Iznos
					,[StazMjeseci1] = @StazMjeseci1
					,[StazMjeseci2] = @StazMjeseci2
					,[MIO1] = @MIO1
					,[MIO2] = @MIO2
					,[BrojDanaInozemstva] = @BrojDanaInozemstva
					,[StazSPovecanimTrajanjemRegos] = @StazSPovecanimTrajanjemRegos
					,[IznosSOsobaPlace] = @IznosSOsobaPlace
					,[DnevnoRadnihSatiSOsobaplaca] = @DnevnoRadnihSatiSOsobaplaca
					,[OriginalniIznos] = @OriginalniIznos
					,[DoprinosNaPlace] = @DoprinosNaPlace
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPrimanje_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPrimanje_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPrimanje_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracunOsobaPrimanje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPrimanje_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblObracunOsobaPrimanje] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPrimanje_GetByIDObracunOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPrimanje_GetByIDObracunOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPrimanje_GetByIDObracunOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsobaPrimanje table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPrimanje_GetByIDObracunOsoba
(

	@IDObracunOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDObracunOsoba],
					[IDPrimanjeTip],
					[Sati],
					[Postotak],
					[Satnica],
					[DatumOd],
					[DatumDo],
					[Iznos],
					[StazMjeseci1],
					[StazMjeseci2],
					[MIO1],
					[MIO2],
					[BrojDanaInozemstva],
					[StazSPovecanimTrajanjemRegos],
					[IznosSOsobaPlace],
					[DnevnoRadnihSatiSOsobaplaca],
					[OriginalniIznos],
					[DoprinosNaPlace]
				FROM
					[pla].[tblObracunOsobaPrimanje]
				WHERE
					[IDObracunOsoba] = @IDObracunOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPrimanje_GetByIDPrimanjeTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPrimanje_GetByIDPrimanjeTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPrimanje_GetByIDPrimanjeTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsobaPrimanje table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPrimanje_GetByIDPrimanjeTip
(

	@IDPrimanjeTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDObracunOsoba],
					[IDPrimanjeTip],
					[Sati],
					[Postotak],
					[Satnica],
					[DatumOd],
					[DatumDo],
					[Iznos],
					[StazMjeseci1],
					[StazMjeseci2],
					[MIO1],
					[MIO2],
					[BrojDanaInozemstva],
					[StazSPovecanimTrajanjemRegos],
					[IznosSOsobaPlace],
					[DnevnoRadnihSatiSOsobaplaca],
					[OriginalniIznos],
					[DoprinosNaPlace]
				FROM
					[pla].[tblObracunOsobaPrimanje]
				WHERE
					[IDPrimanjeTip] = @IDPrimanjeTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPrimanje_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPrimanje_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPrimanje_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsobaPrimanje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPrimanje_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDObracunOsoba],
					[IDPrimanjeTip],
					[Sati],
					[Postotak],
					[Satnica],
					[DatumOd],
					[DatumDo],
					[Iznos],
					[StazMjeseci1],
					[StazMjeseci2],
					[MIO1],
					[MIO2],
					[BrojDanaInozemstva],
					[StazSPovecanimTrajanjemRegos],
					[IznosSOsobaPlace],
					[DnevnoRadnihSatiSOsobaplaca],
					[OriginalniIznos],
					[DoprinosNaPlace]
				FROM
					[pla].[tblObracunOsobaPrimanje]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPrimanje_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPrimanje_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPrimanje_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracunOsobaPrimanje table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPrimanje_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDObracunOsoba int   = null ,

	@IDPrimanjeTip int   = null ,

	@Sati money   = null ,

	@Postotak money   = null ,

	@Satnica real   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@Iznos money   = null ,

	@StazMjeseci1 int   = null ,

	@StazMjeseci2 int   = null ,

	@MIO1 bit   = null ,

	@MIO2 bit   = null ,

	@BrojDanaInozemstva int   = null ,

	@StazSPovecanimTrajanjemRegos int   = null ,

	@IznosSOsobaPlace money   = null ,

	@DnevnoRadnihSatiSOsobaplaca money   = null ,

	@OriginalniIznos money   = null ,

	@DoprinosNaPlace bit   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDObracunOsoba]
	, [IDPrimanjeTip]
	, [Sati]
	, [Postotak]
	, [Satnica]
	, [DatumOd]
	, [DatumDo]
	, [Iznos]
	, [StazMjeseci1]
	, [StazMjeseci2]
	, [MIO1]
	, [MIO2]
	, [BrojDanaInozemstva]
	, [StazSPovecanimTrajanjemRegos]
	, [IznosSOsobaPlace]
	, [DnevnoRadnihSatiSOsobaplaca]
	, [OriginalniIznos]
	, [DoprinosNaPlace]
    FROM
	[pla].[tblObracunOsobaPrimanje]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDObracunOsoba] = @IDObracunOsoba OR @IDObracunOsoba is null)
	AND ([IDPrimanjeTip] = @IDPrimanjeTip OR @IDPrimanjeTip is null)
	AND ([Sati] = @Sati OR @Sati is null)
	AND ([Postotak] = @Postotak OR @Postotak is null)
	AND ([Satnica] = @Satnica OR @Satnica is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
	AND ([StazMjeseci1] = @StazMjeseci1 OR @StazMjeseci1 is null)
	AND ([StazMjeseci2] = @StazMjeseci2 OR @StazMjeseci2 is null)
	AND ([MIO1] = @MIO1 OR @MIO1 is null)
	AND ([MIO2] = @MIO2 OR @MIO2 is null)
	AND ([BrojDanaInozemstva] = @BrojDanaInozemstva OR @BrojDanaInozemstva is null)
	AND ([StazSPovecanimTrajanjemRegos] = @StazSPovecanimTrajanjemRegos OR @StazSPovecanimTrajanjemRegos is null)
	AND ([IznosSOsobaPlace] = @IznosSOsobaPlace OR @IznosSOsobaPlace is null)
	AND ([DnevnoRadnihSatiSOsobaplaca] = @DnevnoRadnihSatiSOsobaplaca OR @DnevnoRadnihSatiSOsobaplaca is null)
	AND ([OriginalniIznos] = @OriginalniIznos OR @OriginalniIznos is null)
	AND ([DoprinosNaPlace] = @DoprinosNaPlace OR @DoprinosNaPlace is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDObracunOsoba]
	, [IDPrimanjeTip]
	, [Sati]
	, [Postotak]
	, [Satnica]
	, [DatumOd]
	, [DatumDo]
	, [Iznos]
	, [StazMjeseci1]
	, [StazMjeseci2]
	, [MIO1]
	, [MIO2]
	, [BrojDanaInozemstva]
	, [StazSPovecanimTrajanjemRegos]
	, [IznosSOsobaPlace]
	, [DnevnoRadnihSatiSOsobaplaca]
	, [OriginalniIznos]
	, [DoprinosNaPlace]
    FROM
	[pla].[tblObracunOsobaPrimanje]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDObracunOsoba] = @IDObracunOsoba AND @IDObracunOsoba is not null)
	OR ([IDPrimanjeTip] = @IDPrimanjeTip AND @IDPrimanjeTip is not null)
	OR ([Sati] = @Sati AND @Sati is not null)
	OR ([Postotak] = @Postotak AND @Postotak is not null)
	OR ([Satnica] = @Satnica AND @Satnica is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	OR ([StazMjeseci1] = @StazMjeseci1 AND @StazMjeseci1 is not null)
	OR ([StazMjeseci2] = @StazMjeseci2 AND @StazMjeseci2 is not null)
	OR ([MIO1] = @MIO1 AND @MIO1 is not null)
	OR ([MIO2] = @MIO2 AND @MIO2 is not null)
	OR ([BrojDanaInozemstva] = @BrojDanaInozemstva AND @BrojDanaInozemstva is not null)
	OR ([StazSPovecanimTrajanjemRegos] = @StazSPovecanimTrajanjemRegos AND @StazSPovecanimTrajanjemRegos is not null)
	OR ([IznosSOsobaPlace] = @IznosSOsobaPlace AND @IznosSOsobaPlace is not null)
	OR ([DnevnoRadnihSatiSOsobaplaca] = @DnevnoRadnihSatiSOsobaplaca AND @DnevnoRadnihSatiSOsobaplaca is not null)
	OR ([OriginalniIznos] = @OriginalniIznos AND @OriginalniIznos is not null)
	OR ([DoprinosNaPlace] = @DoprinosNaPlace AND @DoprinosNaPlace is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDokumentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[OblikSifre],
					[Smjer],
					[Rezervacija],
					[Predracun],
					[IDParent],
					[IDPrebrojavanja]
				FROM
					[dbo].[tblDokumentTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDokumentTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [OblikSifre]'
				SET @SQL = @SQL + ', [Smjer]'
				SET @SQL = @SQL + ', [Rezervacija]'
				SET @SQL = @SQL + ', [Predracun]'
				SET @SQL = @SQL + ', [IDParent]'
				SET @SQL = @SQL + ', [IDPrebrojavanja]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [OblikSifre],'
				SET @SQL = @SQL + ' [Smjer],'
				SET @SQL = @SQL + ' [Rezervacija],'
				SET @SQL = @SQL + ' [Predracun],'
				SET @SQL = @SQL + ' [IDParent],'
				SET @SQL = @SQL + ' [IDPrebrojavanja]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDokumentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentTip_Insert
(

	@ID int   ,

	@Naziv nvarchar (150)  ,

	@OblikSifre nvarchar (50)  ,

	@Smjer int   ,

	@Rezervacija int   ,

	@Predracun int   ,

	@IDParent int   ,

	@IDPrebrojavanja int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDokumentTip]
					(
					[ID]
					,[Naziv]
					,[OblikSifre]
					,[Smjer]
					,[Rezervacija]
					,[Predracun]
					,[IDParent]
					,[IDPrebrojavanja]
					)
				VALUES
					(
					@ID
					,@Naziv
					,@OblikSifre
					,@Smjer
					,@Rezervacija
					,@Predracun
					,@IDParent
					,@IDPrebrojavanja
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDokumentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentTip_Update
(

	@ID int   ,

	@OriginalID int   ,

	@Naziv nvarchar (150)  ,

	@OblikSifre nvarchar (50)  ,

	@Smjer int   ,

	@Rezervacija int   ,

	@Predracun int   ,

	@IDParent int   ,

	@IDPrebrojavanja int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDokumentTip]
				SET
					[ID] = @ID
					,[Naziv] = @Naziv
					,[OblikSifre] = @OblikSifre
					,[Smjer] = @Smjer
					,[Rezervacija] = @Rezervacija
					,[Predracun] = @Predracun
					,[IDParent] = @IDParent
					,[IDPrebrojavanja] = @IDPrebrojavanja
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDokumentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDokumentTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentTip_GetByNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentTip_GetByNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentTip_GetByNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentTip_GetByNaziv
(

	@Naziv nvarchar (150)  
)
AS


				SELECT
					[ID],
					[Naziv],
					[OblikSifre],
					[Smjer],
					[Rezervacija],
					[Predracun],
					[IDParent],
					[IDPrebrojavanja]
				FROM
					[dbo].[tblDokumentTip]
				WHERE
					[Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[OblikSifre],
					[Smjer],
					[Rezervacija],
					[Predracun],
					[IDParent],
					[IDPrebrojavanja]
				FROM
					[dbo].[tblDokumentTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDokumentTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (150)  = null ,

	@OblikSifre nvarchar (50)  = null ,

	@Smjer int   = null ,

	@Rezervacija int   = null ,

	@Predracun int   = null ,

	@IDParent int   = null ,

	@IDPrebrojavanja int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [OblikSifre]
	, [Smjer]
	, [Rezervacija]
	, [Predracun]
	, [IDParent]
	, [IDPrebrojavanja]
    FROM
	[dbo].[tblDokumentTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([OblikSifre] = @OblikSifre OR @OblikSifre is null)
	AND ([Smjer] = @Smjer OR @Smjer is null)
	AND ([Rezervacija] = @Rezervacija OR @Rezervacija is null)
	AND ([Predracun] = @Predracun OR @Predracun is null)
	AND ([IDParent] = @IDParent OR @IDParent is null)
	AND ([IDPrebrojavanja] = @IDPrebrojavanja OR @IDPrebrojavanja is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [OblikSifre]
	, [Smjer]
	, [Rezervacija]
	, [Predracun]
	, [IDParent]
	, [IDPrebrojavanja]
    FROM
	[dbo].[tblDokumentTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([OblikSifre] = @OblikSifre AND @OblikSifre is not null)
	OR ([Smjer] = @Smjer AND @Smjer is not null)
	OR ([Rezervacija] = @Rezervacija AND @Rezervacija is not null)
	OR ([Predracun] = @Predracun AND @Predracun is not null)
	OR ([IDParent] = @IDParent AND @IDParent is not null)
	OR ([IDPrebrojavanja] = @IDPrebrojavanja AND @IDPrebrojavanja is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnik_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnik_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnik_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDjelatnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnik_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[PrikaznoIme],
					[IDOrganizacija]
				FROM
					[dbo].[tblDjelatnik]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnik_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnik_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnik_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDjelatnik table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnik_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [PrikaznoIme]'
				SET @SQL = @SQL + ', [IDOrganizacija]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDjelatnik]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [PrikaznoIme],'
				SET @SQL = @SQL + ' [IDOrganizacija]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDjelatnik]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnik_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnik_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnik_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDjelatnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnik_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  ,

	@PrikaznoIme nvarchar (200)  ,

	@IDOrganizacija int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDjelatnik]
					(
					[Naziv]
					,[PrikaznoIme]
					,[IDOrganizacija]
					)
				VALUES
					(
					@Naziv
					,@PrikaznoIme
					,@IDOrganizacija
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnik_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnik_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnik_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDjelatnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnik_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  ,

	@PrikaznoIme nvarchar (200)  ,

	@IDOrganizacija int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDjelatnik]
				SET
					[Naziv] = @Naziv
					,[PrikaznoIme] = @PrikaznoIme
					,[IDOrganizacija] = @IDOrganizacija
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnik_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnik_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnik_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDjelatnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnik_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDjelatnik] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnik_GetByIDOrganizacija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnik_GetByIDOrganizacija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnik_GetByIDOrganizacija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDjelatnik table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnik_GetByIDOrganizacija
(

	@IDOrganizacija int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[PrikaznoIme],
					[IDOrganizacija]
				FROM
					[dbo].[tblDjelatnik]
				WHERE
					[IDOrganizacija] = @IDOrganizacija
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnik_GetByNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnik_GetByNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnik_GetByNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDjelatnik table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnik_GetByNaziv
(

	@Naziv nvarchar (50)  
)
AS


				SELECT
					[ID],
					[Naziv],
					[PrikaznoIme],
					[IDOrganizacija]
				FROM
					[dbo].[tblDjelatnik]
				WHERE
					[Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnik_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnik_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnik_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDjelatnik table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnik_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[PrikaznoIme],
					[IDOrganizacija]
				FROM
					[dbo].[tblDjelatnik]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnik_GetByIDGrupaDjelatnikFromDjelatnikInGrupa procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnik_GetByIDGrupaDjelatnikFromDjelatnikInGrupa') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnik_GetByIDGrupaDjelatnikFromDjelatnikInGrupa
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records through a junction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnik_GetByIDGrupaDjelatnikFromDjelatnikInGrupa
(

	@IDGrupaDjelatnik int   
)
AS


SELECT dbo.[tblDjelatnik].[ID]
       ,dbo.[tblDjelatnik].[Naziv]
       ,dbo.[tblDjelatnik].[PrikaznoIme]
       ,dbo.[tblDjelatnik].[IDOrganizacija]
  FROM dbo.[tblDjelatnik]
 WHERE EXISTS (SELECT 1
                 FROM dbo.[tblDjelatnikInGrupa] 
                WHERE dbo.[tblDjelatnikInGrupa].[IDGrupaDjelatnik] = @IDGrupaDjelatnik
                  AND dbo.[tblDjelatnikInGrupa].[IDDjelatnik] = dbo.[tblDjelatnik].[ID]
                  )
				Select @@ROWCOUNT			
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnik_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnik_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnik_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDjelatnik table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnik_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null ,

	@PrikaznoIme nvarchar (200)  = null ,

	@IDOrganizacija int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [PrikaznoIme]
	, [IDOrganizacija]
    FROM
	[dbo].[tblDjelatnik]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([PrikaznoIme] = @PrikaznoIme OR @PrikaznoIme is null)
	AND ([IDOrganizacija] = @IDOrganizacija OR @IDOrganizacija is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [PrikaznoIme]
	, [IDOrganizacija]
    FROM
	[dbo].[tblDjelatnik]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([PrikaznoIme] = @PrikaznoIme AND @PrikaznoIme is not null)
	OR ([IDOrganizacija] = @IDOrganizacija AND @IDOrganizacija is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentDodatak_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentDodatak_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentDodatak_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDokumentDodatak table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentDodatak_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokument],
					[Opis],
					[Iznos]
				FROM
					[dbo].[tblDokumentDodatak]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentDodatak_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentDodatak_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentDodatak_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDokumentDodatak table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentDodatak_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDDokument]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentDodatak]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDDokument],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [Iznos]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentDodatak]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentDodatak_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentDodatak_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentDodatak_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDokumentDodatak table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentDodatak_Insert
(

	@ID int    OUTPUT,

	@IDDokument int   ,

	@Opis nvarchar (200)  ,

	@Iznos money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDokumentDodatak]
					(
					[IDDokument]
					,[Opis]
					,[Iznos]
					)
				VALUES
					(
					@IDDokument
					,@Opis
					,@Iznos
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentDodatak_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentDodatak_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentDodatak_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDokumentDodatak table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentDodatak_Update
(

	@ID int   ,

	@IDDokument int   ,

	@Opis nvarchar (200)  ,

	@Iznos money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDokumentDodatak]
				SET
					[IDDokument] = @IDDokument
					,[Opis] = @Opis
					,[Iznos] = @Iznos
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentDodatak_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentDodatak_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentDodatak_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDokumentDodatak table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentDodatak_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDokumentDodatak] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentDodatak_GetByIDDokument procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentDodatak_GetByIDDokument') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentDodatak_GetByIDDokument
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentDodatak table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentDodatak_GetByIDDokument
(

	@IDDokument int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokument],
					[Opis],
					[Iznos]
				FROM
					[dbo].[tblDokumentDodatak]
				WHERE
					[IDDokument] = @IDDokument
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentDodatak_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentDodatak_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentDodatak_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentDodatak table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentDodatak_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDDokument],
					[Opis],
					[Iznos]
				FROM
					[dbo].[tblDokumentDodatak]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentDodatak_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentDodatak_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentDodatak_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDokumentDodatak table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentDodatak_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDDokument int   = null ,

	@Opis nvarchar (200)  = null ,

	@Iznos money   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDDokument]
	, [Opis]
	, [Iznos]
    FROM
	[dbo].[tblDokumentDodatak]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDDokument] = @IDDokument OR @IDDokument is null)
	AND ([Opis] = @Opis OR @Opis is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDDokument]
	, [Opis]
	, [Iznos]
    FROM
	[dbo].[tblDokumentDodatak]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDDokument] = @IDDokument AND @IDDokument is not null)
	OR ([Opis] = @Opis AND @Opis is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDokumentStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDokumentStavka table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOrgJedOd]'
				SET @SQL = @SQL + ', [IDArtikl]'
				SET @SQL = @SQL + ', [Kolicina]'
				SET @SQL = @SQL + ', [Kolicina2]'
				SET @SQL = @SQL + ', [Kolicina3]'
				SET @SQL = @SQL + ', [Kolicina4]'
				SET @SQL = @SQL + ', [Vrijednost]'
				SET @SQL = @SQL + ', [Vrijednost2]'
				SET @SQL = @SQL + ', [Vrijednost3]'
				SET @SQL = @SQL + ', [Vrijednost4]'
				SET @SQL = @SQL + ', [Postotak]'
				SET @SQL = @SQL + ', [Postotak2]'
				SET @SQL = @SQL + ', [Postotak3]'
				SET @SQL = @SQL + ', [Postotak4]'
				SET @SQL = @SQL + ', [Postotak5]'
				SET @SQL = @SQL + ', [IDDokument]'
				SET @SQL = @SQL + ', [IDValuta]'
				SET @SQL = @SQL + ', [IDValuta2]'
				SET @SQL = @SQL + ', [IDUserCreated]'
				SET @SQL = @SQL + ', [IDUserModified]'
				SET @SQL = @SQL + ', [Prilagoden]'
				SET @SQL = @SQL + ', [PrilagodenJedMj]'
				SET @SQL = @SQL + ', [Opisno]'
				SET @SQL = @SQL + ', [DateCreated]'
				SET @SQL = @SQL + ', [DateModified]'
				SET @SQL = @SQL + ', [DateUICreated]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentStavka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOrgJedOd],'
				SET @SQL = @SQL + ' [IDArtikl],'
				SET @SQL = @SQL + ' [Kolicina],'
				SET @SQL = @SQL + ' [Kolicina2],'
				SET @SQL = @SQL + ' [Kolicina3],'
				SET @SQL = @SQL + ' [Kolicina4],'
				SET @SQL = @SQL + ' [Vrijednost],'
				SET @SQL = @SQL + ' [Vrijednost2],'
				SET @SQL = @SQL + ' [Vrijednost3],'
				SET @SQL = @SQL + ' [Vrijednost4],'
				SET @SQL = @SQL + ' [Postotak],'
				SET @SQL = @SQL + ' [Postotak2],'
				SET @SQL = @SQL + ' [Postotak3],'
				SET @SQL = @SQL + ' [Postotak4],'
				SET @SQL = @SQL + ' [Postotak5],'
				SET @SQL = @SQL + ' [IDDokument],'
				SET @SQL = @SQL + ' [IDValuta],'
				SET @SQL = @SQL + ' [IDValuta2],'
				SET @SQL = @SQL + ' [IDUserCreated],'
				SET @SQL = @SQL + ' [IDUserModified],'
				SET @SQL = @SQL + ' [Prilagoden],'
				SET @SQL = @SQL + ' [PrilagodenJedMj],'
				SET @SQL = @SQL + ' [Opisno],'
				SET @SQL = @SQL + ' [DateCreated],'
				SET @SQL = @SQL + ' [DateModified],'
				SET @SQL = @SQL + ' [DateUICreated]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentStavka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDokumentStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_Insert
(

	@ID int    OUTPUT,

	@IDOrgJedOd int   ,

	@IDArtikl int   ,

	@Kolicina real   ,

	@Kolicina2 real   ,

	@Kolicina3 real   ,

	@Kolicina4 real   ,

	@Vrijednost money   ,

	@Vrijednost2 money   ,

	@Vrijednost3 money   ,

	@Vrijednost4 money   ,

	@Postotak real   ,

	@Postotak2 real   ,

	@Postotak3 real   ,

	@Postotak4 real   ,

	@Postotak5 real   ,

	@IDDokument int   ,

	@IDValuta int   ,

	@IDValuta2 int   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@Prilagoden nvarchar (400)  ,

	@PrilagodenJedMj nvarchar (50)  ,

	@Opisno nvarchar (200)  ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@DateUICreated datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDokumentStavka]
					(
					[IDOrgJedOd]
					,[IDArtikl]
					,[Kolicina]
					,[Kolicina2]
					,[Kolicina3]
					,[Kolicina4]
					,[Vrijednost]
					,[Vrijednost2]
					,[Vrijednost3]
					,[Vrijednost4]
					,[Postotak]
					,[Postotak2]
					,[Postotak3]
					,[Postotak4]
					,[Postotak5]
					,[IDDokument]
					,[IDValuta]
					,[IDValuta2]
					,[IDUserCreated]
					,[IDUserModified]
					,[Prilagoden]
					,[PrilagodenJedMj]
					,[Opisno]
					,[DateCreated]
					,[DateModified]
					,[DateUICreated]
					)
				VALUES
					(
					@IDOrgJedOd
					,@IDArtikl
					,@Kolicina
					,@Kolicina2
					,@Kolicina3
					,@Kolicina4
					,@Vrijednost
					,@Vrijednost2
					,@Vrijednost3
					,@Vrijednost4
					,@Postotak
					,@Postotak2
					,@Postotak3
					,@Postotak4
					,@Postotak5
					,@IDDokument
					,@IDValuta
					,@IDValuta2
					,@IDUserCreated
					,@IDUserModified
					,@Prilagoden
					,@PrilagodenJedMj
					,@Opisno
					,@DateCreated
					,@DateModified
					,@DateUICreated
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDokumentStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_Update
(

	@ID int   ,

	@IDOrgJedOd int   ,

	@IDArtikl int   ,

	@Kolicina real   ,

	@Kolicina2 real   ,

	@Kolicina3 real   ,

	@Kolicina4 real   ,

	@Vrijednost money   ,

	@Vrijednost2 money   ,

	@Vrijednost3 money   ,

	@Vrijednost4 money   ,

	@Postotak real   ,

	@Postotak2 real   ,

	@Postotak3 real   ,

	@Postotak4 real   ,

	@Postotak5 real   ,

	@IDDokument int   ,

	@IDValuta int   ,

	@IDValuta2 int   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@Prilagoden nvarchar (400)  ,

	@PrilagodenJedMj nvarchar (50)  ,

	@Opisno nvarchar (200)  ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@DateUICreated datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDokumentStavka]
				SET
					[IDOrgJedOd] = @IDOrgJedOd
					,[IDArtikl] = @IDArtikl
					,[Kolicina] = @Kolicina
					,[Kolicina2] = @Kolicina2
					,[Kolicina3] = @Kolicina3
					,[Kolicina4] = @Kolicina4
					,[Vrijednost] = @Vrijednost
					,[Vrijednost2] = @Vrijednost2
					,[Vrijednost3] = @Vrijednost3
					,[Vrijednost4] = @Vrijednost4
					,[Postotak] = @Postotak
					,[Postotak2] = @Postotak2
					,[Postotak3] = @Postotak3
					,[Postotak4] = @Postotak4
					,[Postotak5] = @Postotak5
					,[IDDokument] = @IDDokument
					,[IDValuta] = @IDValuta
					,[IDValuta2] = @IDValuta2
					,[IDUserCreated] = @IDUserCreated
					,[IDUserModified] = @IDUserModified
					,[Prilagoden] = @Prilagoden
					,[PrilagodenJedMj] = @PrilagodenJedMj
					,[Opisno] = @Opisno
					,[DateCreated] = @DateCreated
					,[DateModified] = @DateModified
					,[DateUICreated] = @DateUICreated
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDokumentStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDokumentStavka] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDArtikl procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDArtikl') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDArtikl
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDArtikl
(

	@IDArtikl int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDArtikl] = @IDArtikl
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDUserModified procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDUserModified') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDUserModified
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDUserModified
(

	@IDUserModified int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDUserModified] = @IDUserModified
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDDokument procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDDokument') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDDokument
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDDokument
(

	@IDDokument int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDDokument] = @IDDokument
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDValuta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDValuta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDValuta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDValuta
(

	@IDValuta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDValuta] = @IDValuta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDValuta2 procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDValuta2') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDValuta2
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDValuta2
(

	@IDValuta2 int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDValuta2] = @IDValuta2
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDOrgJedOdIDArtiklIDDokument procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDOrgJedOdIDArtiklIDDokument') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDOrgJedOdIDArtiklIDDokument
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDOrgJedOdIDArtiklIDDokument
(

	@IDOrgJedOd int   ,

	@IDArtikl int   ,

	@IDDokument int   
)
AS


				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDOrgJedOd] = @IDOrgJedOd
					AND [IDArtikl] = @IDArtikl
					AND [IDDokument] = @IDDokument
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDArtiklIDOrgJedOd procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDArtiklIDOrgJedOd') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDArtiklIDOrgJedOd
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDArtiklIDOrgJedOd
(

	@IDArtikl int   ,

	@IDOrgJedOd int   
)
AS


				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDArtikl] = @IDArtikl
					AND [IDOrgJedOd] = @IDOrgJedOd
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDDokumentIDArtiklIDIDOrgJedOdVrijednost3 procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDDokumentIDArtiklIDIDOrgJedOdVrijednost3') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDDokumentIDArtiklIDIDOrgJedOdVrijednost3
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDDokumentIDArtiklIDIDOrgJedOdVrijednost3
(

	@IDDokument int   ,

	@IDArtikl int   ,

	@ID int   ,

	@IDOrgJedOd int   ,

	@Vrijednost3 money   
)
AS


				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDDokument] = @IDDokument
					AND [IDArtikl] = @IDArtikl
					AND [ID] = @ID
					AND [IDOrgJedOd] = @IDOrgJedOd
					AND [Vrijednost3] = @Vrijednost3
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDOrgJedOdIDArtikl procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDOrgJedOdIDArtikl') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDOrgJedOdIDArtikl
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDOrgJedOdIDArtikl
(

	@IDOrgJedOd int   ,

	@IDArtikl int   
)
AS


				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDOrgJedOd] = @IDOrgJedOd
					AND [IDArtikl] = @IDArtikl
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDDokumentIDOrgJedOdIDArtikl procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDDokumentIDOrgJedOdIDArtikl') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDDokumentIDOrgJedOdIDArtikl
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDDokumentIDOrgJedOdIDArtikl
(

	@IDDokument int   ,

	@IDOrgJedOd int   ,

	@IDArtikl int   
)
AS


				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDDokument] = @IDDokument
					AND [IDOrgJedOd] = @IDOrgJedOd
					AND [IDArtikl] = @IDArtikl
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDDokumentIDArtiklIDOrgJedOd procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDDokumentIDArtiklIDOrgJedOd') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDDokumentIDArtiklIDOrgJedOd
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDDokumentIDArtiklIDOrgJedOd
(

	@IDDokument int   ,

	@IDArtikl int   ,

	@IDOrgJedOd int   
)
AS


				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDDokument] = @IDDokument
					AND [IDArtikl] = @IDArtikl
					AND [IDOrgJedOd] = @IDOrgJedOd
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByIDOrgJedOd procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByIDOrgJedOd') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByIDOrgJedOd
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByIDOrgJedOd
(

	@IDOrgJedOd int   
)
AS


				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[IDOrgJedOd] = @IDOrgJedOd
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOrgJedOd],
					[IDArtikl],
					[Kolicina],
					[Kolicina2],
					[Kolicina3],
					[Kolicina4],
					[Vrijednost],
					[Vrijednost2],
					[Vrijednost3],
					[Vrijednost4],
					[Postotak],
					[Postotak2],
					[Postotak3],
					[Postotak4],
					[Postotak5],
					[IDDokument],
					[IDValuta],
					[IDValuta2],
					[IDUserCreated],
					[IDUserModified],
					[Prilagoden],
					[PrilagodenJedMj],
					[Opisno],
					[DateCreated],
					[DateModified],
					[DateUICreated]
				FROM
					[dbo].[tblDokumentStavka]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavka_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavka_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavka_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDokumentStavka table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavka_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOrgJedOd int   = null ,

	@IDArtikl int   = null ,

	@Kolicina real   = null ,

	@Kolicina2 real   = null ,

	@Kolicina3 real   = null ,

	@Kolicina4 real   = null ,

	@Vrijednost money   = null ,

	@Vrijednost2 money   = null ,

	@Vrijednost3 money   = null ,

	@Vrijednost4 money   = null ,

	@Postotak real   = null ,

	@Postotak2 real   = null ,

	@Postotak3 real   = null ,

	@Postotak4 real   = null ,

	@Postotak5 real   = null ,

	@IDDokument int   = null ,

	@IDValuta int   = null ,

	@IDValuta2 int   = null ,

	@IDUserCreated int   = null ,

	@IDUserModified int   = null ,

	@Prilagoden nvarchar (400)  = null ,

	@PrilagodenJedMj nvarchar (50)  = null ,

	@Opisno nvarchar (200)  = null ,

	@DateCreated datetime   = null ,

	@DateModified datetime   = null ,

	@DateUICreated datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOrgJedOd]
	, [IDArtikl]
	, [Kolicina]
	, [Kolicina2]
	, [Kolicina3]
	, [Kolicina4]
	, [Vrijednost]
	, [Vrijednost2]
	, [Vrijednost3]
	, [Vrijednost4]
	, [Postotak]
	, [Postotak2]
	, [Postotak3]
	, [Postotak4]
	, [Postotak5]
	, [IDDokument]
	, [IDValuta]
	, [IDValuta2]
	, [IDUserCreated]
	, [IDUserModified]
	, [Prilagoden]
	, [PrilagodenJedMj]
	, [Opisno]
	, [DateCreated]
	, [DateModified]
	, [DateUICreated]
    FROM
	[dbo].[tblDokumentStavka]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOrgJedOd] = @IDOrgJedOd OR @IDOrgJedOd is null)
	AND ([IDArtikl] = @IDArtikl OR @IDArtikl is null)
	AND ([Kolicina] = @Kolicina OR @Kolicina is null)
	AND ([Kolicina2] = @Kolicina2 OR @Kolicina2 is null)
	AND ([Kolicina3] = @Kolicina3 OR @Kolicina3 is null)
	AND ([Kolicina4] = @Kolicina4 OR @Kolicina4 is null)
	AND ([Vrijednost] = @Vrijednost OR @Vrijednost is null)
	AND ([Vrijednost2] = @Vrijednost2 OR @Vrijednost2 is null)
	AND ([Vrijednost3] = @Vrijednost3 OR @Vrijednost3 is null)
	AND ([Vrijednost4] = @Vrijednost4 OR @Vrijednost4 is null)
	AND ([Postotak] = @Postotak OR @Postotak is null)
	AND ([Postotak2] = @Postotak2 OR @Postotak2 is null)
	AND ([Postotak3] = @Postotak3 OR @Postotak3 is null)
	AND ([Postotak4] = @Postotak4 OR @Postotak4 is null)
	AND ([Postotak5] = @Postotak5 OR @Postotak5 is null)
	AND ([IDDokument] = @IDDokument OR @IDDokument is null)
	AND ([IDValuta] = @IDValuta OR @IDValuta is null)
	AND ([IDValuta2] = @IDValuta2 OR @IDValuta2 is null)
	AND ([IDUserCreated] = @IDUserCreated OR @IDUserCreated is null)
	AND ([IDUserModified] = @IDUserModified OR @IDUserModified is null)
	AND ([Prilagoden] = @Prilagoden OR @Prilagoden is null)
	AND ([PrilagodenJedMj] = @PrilagodenJedMj OR @PrilagodenJedMj is null)
	AND ([Opisno] = @Opisno OR @Opisno is null)
	AND ([DateCreated] = @DateCreated OR @DateCreated is null)
	AND ([DateModified] = @DateModified OR @DateModified is null)
	AND ([DateUICreated] = @DateUICreated OR @DateUICreated is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOrgJedOd]
	, [IDArtikl]
	, [Kolicina]
	, [Kolicina2]
	, [Kolicina3]
	, [Kolicina4]
	, [Vrijednost]
	, [Vrijednost2]
	, [Vrijednost3]
	, [Vrijednost4]
	, [Postotak]
	, [Postotak2]
	, [Postotak3]
	, [Postotak4]
	, [Postotak5]
	, [IDDokument]
	, [IDValuta]
	, [IDValuta2]
	, [IDUserCreated]
	, [IDUserModified]
	, [Prilagoden]
	, [PrilagodenJedMj]
	, [Opisno]
	, [DateCreated]
	, [DateModified]
	, [DateUICreated]
    FROM
	[dbo].[tblDokumentStavka]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOrgJedOd] = @IDOrgJedOd AND @IDOrgJedOd is not null)
	OR ([IDArtikl] = @IDArtikl AND @IDArtikl is not null)
	OR ([Kolicina] = @Kolicina AND @Kolicina is not null)
	OR ([Kolicina2] = @Kolicina2 AND @Kolicina2 is not null)
	OR ([Kolicina3] = @Kolicina3 AND @Kolicina3 is not null)
	OR ([Kolicina4] = @Kolicina4 AND @Kolicina4 is not null)
	OR ([Vrijednost] = @Vrijednost AND @Vrijednost is not null)
	OR ([Vrijednost2] = @Vrijednost2 AND @Vrijednost2 is not null)
	OR ([Vrijednost3] = @Vrijednost3 AND @Vrijednost3 is not null)
	OR ([Vrijednost4] = @Vrijednost4 AND @Vrijednost4 is not null)
	OR ([Postotak] = @Postotak AND @Postotak is not null)
	OR ([Postotak2] = @Postotak2 AND @Postotak2 is not null)
	OR ([Postotak3] = @Postotak3 AND @Postotak3 is not null)
	OR ([Postotak4] = @Postotak4 AND @Postotak4 is not null)
	OR ([Postotak5] = @Postotak5 AND @Postotak5 is not null)
	OR ([IDDokument] = @IDDokument AND @IDDokument is not null)
	OR ([IDValuta] = @IDValuta AND @IDValuta is not null)
	OR ([IDValuta2] = @IDValuta2 AND @IDValuta2 is not null)
	OR ([IDUserCreated] = @IDUserCreated AND @IDUserCreated is not null)
	OR ([IDUserModified] = @IDUserModified AND @IDUserModified is not null)
	OR ([Prilagoden] = @Prilagoden AND @Prilagoden is not null)
	OR ([PrilagodenJedMj] = @PrilagodenJedMj AND @PrilagodenJedMj is not null)
	OR ([Opisno] = @Opisno AND @Opisno is not null)
	OR ([DateCreated] = @DateCreated AND @DateCreated is not null)
	OR ([DateModified] = @DateModified AND @DateModified is not null)
	OR ([DateUICreated] = @DateUICreated AND @DateUICreated is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblDnevnica_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblDnevnica_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblDnevnica_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDnevnica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblDnevnica_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Iznos]
				FROM
					[fin].[tblDnevnica]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblDnevnica_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblDnevnica_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblDnevnica_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDnevnica table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblDnevnica_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ' FROM [fin].[tblDnevnica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Iznos]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblDnevnica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblDnevnica_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblDnevnica_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblDnevnica_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDnevnica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblDnevnica_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  ,

	@Iznos money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblDnevnica]
					(
					[Naziv]
					,[Iznos]
					)
				VALUES
					(
					@Naziv
					,@Iznos
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblDnevnica_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblDnevnica_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblDnevnica_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDnevnica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblDnevnica_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  ,

	@Iznos money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblDnevnica]
				SET
					[Naziv] = @Naziv
					,[Iznos] = @Iznos
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblDnevnica_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblDnevnica_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblDnevnica_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDnevnica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblDnevnica_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblDnevnica] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblDnevnica_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblDnevnica_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblDnevnica_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDnevnica table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblDnevnica_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[Iznos]
				FROM
					[fin].[tblDnevnica]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblDnevnica_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblDnevnica_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblDnevnica_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDnevnica table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblDnevnica_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null ,

	@Iznos money   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Iznos]
    FROM
	[fin].[tblDnevnica]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Iznos]
    FROM
	[fin].[tblDnevnica]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnikInGrupa_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnikInGrupa_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnikInGrupa_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDjelatnikInGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnikInGrupa_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDDjelatnik],
					[IDGrupaDjelatnik]
				FROM
					[dbo].[tblDjelatnikInGrupa]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnikInGrupa_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnikInGrupa_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnikInGrupa_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDjelatnikInGrupa table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnikInGrupa_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDDjelatnik]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDDjelatnik]'
				SET @SQL = @SQL + ', [IDGrupaDjelatnik]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDjelatnikInGrupa]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDDjelatnik],'
				SET @SQL = @SQL + ' [IDGrupaDjelatnik]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDjelatnikInGrupa]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnikInGrupa_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnikInGrupa_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnikInGrupa_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDjelatnikInGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnikInGrupa_Insert
(

	@IDDjelatnik int   ,

	@IDGrupaDjelatnik int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDjelatnikInGrupa]
					(
					[IDDjelatnik]
					,[IDGrupaDjelatnik]
					)
				VALUES
					(
					@IDDjelatnik
					,@IDGrupaDjelatnik
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnikInGrupa_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnikInGrupa_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnikInGrupa_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDjelatnikInGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnikInGrupa_Update
(

	@IDDjelatnik int   ,

	@OriginalIDDjelatnik int   ,

	@IDGrupaDjelatnik int   ,

	@OriginalIDGrupaDjelatnik int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDjelatnikInGrupa]
				SET
					[IDDjelatnik] = @IDDjelatnik
					,[IDGrupaDjelatnik] = @IDGrupaDjelatnik
				WHERE
[IDDjelatnik] = @OriginalIDDjelatnik 
AND [IDGrupaDjelatnik] = @OriginalIDGrupaDjelatnik 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnikInGrupa_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnikInGrupa_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnikInGrupa_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDjelatnikInGrupa table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnikInGrupa_Delete
(

	@IDDjelatnik int   ,

	@IDGrupaDjelatnik int   
)
AS


				DELETE FROM [dbo].[tblDjelatnikInGrupa] WITH (ROWLOCK) 
				WHERE
					[IDDjelatnik] = @IDDjelatnik
					AND [IDGrupaDjelatnik] = @IDGrupaDjelatnik
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnikInGrupa_GetByIDDjelatnik procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnikInGrupa_GetByIDDjelatnik') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnikInGrupa_GetByIDDjelatnik
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDjelatnikInGrupa table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnikInGrupa_GetByIDDjelatnik
(

	@IDDjelatnik int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDDjelatnik],
					[IDGrupaDjelatnik]
				FROM
					[dbo].[tblDjelatnikInGrupa]
				WHERE
					[IDDjelatnik] = @IDDjelatnik
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnikInGrupa_GetByIDGrupaDjelatnik procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnikInGrupa_GetByIDGrupaDjelatnik') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnikInGrupa_GetByIDGrupaDjelatnik
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDjelatnikInGrupa table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnikInGrupa_GetByIDGrupaDjelatnik
(

	@IDGrupaDjelatnik int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDDjelatnik],
					[IDGrupaDjelatnik]
				FROM
					[dbo].[tblDjelatnikInGrupa]
				WHERE
					[IDGrupaDjelatnik] = @IDGrupaDjelatnik
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnikInGrupa_GetByIDDjelatnikIDGrupaDjelatnik procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnikInGrupa_GetByIDDjelatnikIDGrupaDjelatnik') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnikInGrupa_GetByIDDjelatnikIDGrupaDjelatnik
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDjelatnikInGrupa table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnikInGrupa_GetByIDDjelatnikIDGrupaDjelatnik
(

	@IDDjelatnik int   ,

	@IDGrupaDjelatnik int   
)
AS


				SELECT
					[IDDjelatnik],
					[IDGrupaDjelatnik]
				FROM
					[dbo].[tblDjelatnikInGrupa]
				WHERE
					[IDDjelatnik] = @IDDjelatnik
					AND [IDGrupaDjelatnik] = @IDGrupaDjelatnik
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDjelatnikInGrupa_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDjelatnikInGrupa_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDjelatnikInGrupa_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDjelatnikInGrupa table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDjelatnikInGrupa_Find
(

	@SearchUsingOR bit   = null ,

	@IDDjelatnik int   = null ,

	@IDGrupaDjelatnik int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [IDDjelatnik]
	, [IDGrupaDjelatnik]
    FROM
	[dbo].[tblDjelatnikInGrupa]
    WHERE 
	 ([IDDjelatnik] = @IDDjelatnik OR @IDDjelatnik is null)
	AND ([IDGrupaDjelatnik] = @IDGrupaDjelatnik OR @IDGrupaDjelatnik is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [IDDjelatnik]
	, [IDGrupaDjelatnik]
    FROM
	[dbo].[tblDjelatnikInGrupa]
    WHERE 
	 ([IDDjelatnik] = @IDDjelatnik AND @IDDjelatnik is not null)
	OR ([IDGrupaDjelatnik] = @IDGrupaDjelatnik AND @IDGrupaDjelatnik is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavkaOpis_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavkaOpis_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavkaOpis_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDokumentStavkaOpis table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavkaOpis_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentStavka],
					[Opis]
				FROM
					[dbo].[tblDokumentStavkaOpis]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavkaOpis_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavkaOpis_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavkaOpis_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDokumentStavkaOpis table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavkaOpis_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDDokumentStavka]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentStavkaOpis]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDDokumentStavka],'
				SET @SQL = @SQL + ' [Opis]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentStavkaOpis]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavkaOpis_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavkaOpis_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavkaOpis_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDokumentStavkaOpis table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavkaOpis_Insert
(

	@ID int    OUTPUT,

	@IDDokumentStavka int   ,

	@Opis nvarchar (1000)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDokumentStavkaOpis]
					(
					[IDDokumentStavka]
					,[Opis]
					)
				VALUES
					(
					@IDDokumentStavka
					,@Opis
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavkaOpis_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavkaOpis_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavkaOpis_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDokumentStavkaOpis table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavkaOpis_Update
(

	@ID int   ,

	@IDDokumentStavka int   ,

	@Opis nvarchar (1000)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDokumentStavkaOpis]
				SET
					[IDDokumentStavka] = @IDDokumentStavka
					,[Opis] = @Opis
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavkaOpis_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavkaOpis_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavkaOpis_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDokumentStavkaOpis table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavkaOpis_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDokumentStavkaOpis] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavkaOpis_GetByIDDokumentStavka procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavkaOpis_GetByIDDokumentStavka') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavkaOpis_GetByIDDokumentStavka
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavkaOpis table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavkaOpis_GetByIDDokumentStavka
(

	@IDDokumentStavka int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentStavka],
					[Opis]
				FROM
					[dbo].[tblDokumentStavkaOpis]
				WHERE
					[IDDokumentStavka] = @IDDokumentStavka
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavkaOpis_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavkaOpis_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavkaOpis_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentStavkaOpis table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavkaOpis_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDDokumentStavka],
					[Opis]
				FROM
					[dbo].[tblDokumentStavkaOpis]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentStavkaOpis_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentStavkaOpis_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentStavkaOpis_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDokumentStavkaOpis table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentStavkaOpis_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDDokumentStavka int   = null ,

	@Opis nvarchar (1000)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDDokumentStavka]
	, [Opis]
    FROM
	[dbo].[tblDokumentStavkaOpis]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDDokumentStavka] = @IDDokumentStavka OR @IDDokumentStavka is null)
	AND ([Opis] = @Opis OR @Opis is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDDokumentStavka]
	, [Opis]
    FROM
	[dbo].[tblDokumentStavkaOpis]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDDokumentStavka] = @IDDokumentStavka AND @IDDokumentStavka is not null)
	OR ([Opis] = @Opis AND @Opis is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDokumentZaglavljeSpecTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[TekstZaglavlja],
					[FormatString],
					[FormatTip],
					[DefVrijednost]
				FROM
					[dbo].[tblDokumentZaglavljeSpecTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDokumentZaglavljeSpecTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [TekstZaglavlja]'
				SET @SQL = @SQL + ', [FormatString]'
				SET @SQL = @SQL + ', [FormatTip]'
				SET @SQL = @SQL + ', [DefVrijednost]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentZaglavljeSpecTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [TekstZaglavlja],'
				SET @SQL = @SQL + ' [FormatString],'
				SET @SQL = @SQL + ' [FormatTip],'
				SET @SQL = @SQL + ' [DefVrijednost]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentZaglavljeSpecTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDokumentZaglavljeSpecTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (15)  ,

	@TekstZaglavlja nvarchar (100)  ,

	@FormatString nvarchar (250)  ,

	@FormatTip nvarchar (20)  ,

	@DefVrijednost nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDokumentZaglavljeSpecTip]
					(
					[Naziv]
					,[TekstZaglavlja]
					,[FormatString]
					,[FormatTip]
					,[DefVrijednost]
					)
				VALUES
					(
					@Naziv
					,@TekstZaglavlja
					,@FormatString
					,@FormatTip
					,@DefVrijednost
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDokumentZaglavljeSpecTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecTip_Update
(

	@ID int   ,

	@Naziv nvarchar (15)  ,

	@TekstZaglavlja nvarchar (100)  ,

	@FormatString nvarchar (250)  ,

	@FormatTip nvarchar (20)  ,

	@DefVrijednost nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDokumentZaglavljeSpecTip]
				SET
					[Naziv] = @Naziv
					,[TekstZaglavlja] = @TekstZaglavlja
					,[FormatString] = @FormatString
					,[FormatTip] = @FormatTip
					,[DefVrijednost] = @DefVrijednost
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDokumentZaglavljeSpecTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDokumentZaglavljeSpecTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentZaglavljeSpecTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[TekstZaglavlja],
					[FormatString],
					[FormatTip],
					[DefVrijednost]
				FROM
					[dbo].[tblDokumentZaglavljeSpecTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDokumentZaglavljeSpecTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (15)  = null ,

	@TekstZaglavlja nvarchar (100)  = null ,

	@FormatString nvarchar (250)  = null ,

	@FormatTip nvarchar (20)  = null ,

	@DefVrijednost nvarchar (100)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [TekstZaglavlja]
	, [FormatString]
	, [FormatTip]
	, [DefVrijednost]
    FROM
	[dbo].[tblDokumentZaglavljeSpecTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([TekstZaglavlja] = @TekstZaglavlja OR @TekstZaglavlja is null)
	AND ([FormatString] = @FormatString OR @FormatString is null)
	AND ([FormatTip] = @FormatTip OR @FormatTip is null)
	AND ([DefVrijednost] = @DefVrijednost OR @DefVrijednost is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [TekstZaglavlja]
	, [FormatString]
	, [FormatTip]
	, [DefVrijednost]
    FROM
	[dbo].[tblDokumentZaglavljeSpecTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([TekstZaglavlja] = @TekstZaglavlja AND @TekstZaglavlja is not null)
	OR ([FormatString] = @FormatString AND @FormatString is not null)
	OR ([FormatTip] = @FormatTip AND @FormatTip is not null)
	OR ([DefVrijednost] = @DefVrijednost AND @DefVrijednost is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecPostavke_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecPostavke_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDokumentZaglavljeSpecPostavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDSpecTip],
					[IDDokumentTip],
					[RedBr],
					[Kolona]
				FROM
					[dbo].[tblDokumentZaglavljeSpecPostavke]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecPostavke_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecPostavke_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDokumentZaglavljeSpecPostavke table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDSpecTip]'
				SET @SQL = @SQL + ', [IDDokumentTip]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [Kolona]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentZaglavljeSpecPostavke]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDSpecTip],'
				SET @SQL = @SQL + ' [IDDokumentTip],'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [Kolona]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentZaglavljeSpecPostavke]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecPostavke_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecPostavke_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDokumentZaglavljeSpecPostavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_Insert
(

	@ID int    OUTPUT,

	@IDSpecTip int   ,

	@IDDokumentTip int   ,

	@RedBr int   ,

	@Kolona money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDokumentZaglavljeSpecPostavke]
					(
					[IDSpecTip]
					,[IDDokumentTip]
					,[RedBr]
					,[Kolona]
					)
				VALUES
					(
					@IDSpecTip
					,@IDDokumentTip
					,@RedBr
					,@Kolona
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecPostavke_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecPostavke_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDokumentZaglavljeSpecPostavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_Update
(

	@ID int   ,

	@IDSpecTip int   ,

	@IDDokumentTip int   ,

	@RedBr int   ,

	@Kolona money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDokumentZaglavljeSpecPostavke]
				SET
					[IDSpecTip] = @IDSpecTip
					,[IDDokumentTip] = @IDDokumentTip
					,[RedBr] = @RedBr
					,[Kolona] = @Kolona
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecPostavke_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecPostavke_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDokumentZaglavljeSpecPostavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDokumentZaglavljeSpecPostavke] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecPostavke_GetByIDDokumentTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecPostavke_GetByIDDokumentTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_GetByIDDokumentTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentZaglavljeSpecPostavke table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_GetByIDDokumentTip
(

	@IDDokumentTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDSpecTip],
					[IDDokumentTip],
					[RedBr],
					[Kolona]
				FROM
					[dbo].[tblDokumentZaglavljeSpecPostavke]
				WHERE
					[IDDokumentTip] = @IDDokumentTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecPostavke_GetByIDSpecTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecPostavke_GetByIDSpecTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_GetByIDSpecTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentZaglavljeSpecPostavke table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_GetByIDSpecTip
(

	@IDSpecTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDSpecTip],
					[IDDokumentTip],
					[RedBr],
					[Kolona]
				FROM
					[dbo].[tblDokumentZaglavljeSpecPostavke]
				WHERE
					[IDSpecTip] = @IDSpecTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecPostavke_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecPostavke_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentZaglavljeSpecPostavke table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDSpecTip],
					[IDDokumentTip],
					[RedBr],
					[Kolona]
				FROM
					[dbo].[tblDokumentZaglavljeSpecPostavke]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecPostavke_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecPostavke_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDokumentZaglavljeSpecPostavke table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecPostavke_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDSpecTip int   = null ,

	@IDDokumentTip int   = null ,

	@RedBr int   = null ,

	@Kolona money   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDSpecTip]
	, [IDDokumentTip]
	, [RedBr]
	, [Kolona]
    FROM
	[dbo].[tblDokumentZaglavljeSpecPostavke]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDSpecTip] = @IDSpecTip OR @IDSpecTip is null)
	AND ([IDDokumentTip] = @IDDokumentTip OR @IDDokumentTip is null)
	AND ([RedBr] = @RedBr OR @RedBr is null)
	AND ([Kolona] = @Kolona OR @Kolona is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDSpecTip]
	, [IDDokumentTip]
	, [RedBr]
	, [Kolona]
    FROM
	[dbo].[tblDokumentZaglavljeSpecPostavke]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDSpecTip] = @IDSpecTip AND @IDSpecTip is not null)
	OR ([IDDokumentTip] = @IDDokumentTip AND @IDDokumentTip is not null)
	OR ([RedBr] = @RedBr AND @RedBr is not null)
	OR ([Kolona] = @Kolona AND @Kolona is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaParametra_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaParametra_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaParametra_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblGrupaParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaParametra_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDGrupaParametra],
					[Naziv]
				FROM
					[dbo].[tblGrupaParametra]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaParametra_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaParametra_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaParametra_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblGrupaParametra table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaParametra_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDGrupaParametra]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDGrupaParametra]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [dbo].[tblGrupaParametra]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDGrupaParametra],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblGrupaParametra]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaParametra_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaParametra_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaParametra_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblGrupaParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaParametra_Insert
(

	@IDGrupaParametra int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblGrupaParametra]
					(
					[IDGrupaParametra]
					,[Naziv]
					)
				VALUES
					(
					@IDGrupaParametra
					,@Naziv
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaParametra_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaParametra_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaParametra_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblGrupaParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaParametra_Update
(

	@IDGrupaParametra int   ,

	@OriginalIDGrupaParametra int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblGrupaParametra]
				SET
					[IDGrupaParametra] = @IDGrupaParametra
					,[Naziv] = @Naziv
				WHERE
[IDGrupaParametra] = @OriginalIDGrupaParametra 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaParametra_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaParametra_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaParametra_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblGrupaParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaParametra_Delete
(

	@IDGrupaParametra int   
)
AS


				DELETE FROM [dbo].[tblGrupaParametra] WITH (ROWLOCK) 
				WHERE
					[IDGrupaParametra] = @IDGrupaParametra
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaParametra_GetByIDGrupaParametraNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaParametra_GetByIDGrupaParametraNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaParametra_GetByIDGrupaParametraNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaParametra table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaParametra_GetByIDGrupaParametraNaziv
(

	@IDGrupaParametra int   ,

	@Naziv nvarchar (50)  
)
AS


				SELECT
					[IDGrupaParametra],
					[Naziv]
				FROM
					[dbo].[tblGrupaParametra]
				WHERE
					[IDGrupaParametra] = @IDGrupaParametra
					AND [Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaParametra_GetByIDGrupaParametra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaParametra_GetByIDGrupaParametra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaParametra_GetByIDGrupaParametra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaParametra table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaParametra_GetByIDGrupaParametra
(

	@IDGrupaParametra int   
)
AS


				SELECT
					[IDGrupaParametra],
					[Naziv]
				FROM
					[dbo].[tblGrupaParametra]
				WHERE
					[IDGrupaParametra] = @IDGrupaParametra
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaParametra_GetByIDGrupaDjelatnikFromGrupaDjelatnikParametra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaParametra_GetByIDGrupaDjelatnikFromGrupaDjelatnikParametra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaParametra_GetByIDGrupaDjelatnikFromGrupaDjelatnikParametra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records through a junction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaParametra_GetByIDGrupaDjelatnikFromGrupaDjelatnikParametra
(

	@IDGrupaDjelatnik int   
)
AS


SELECT dbo.[tblGrupaParametra].[IDGrupaParametra]
       ,dbo.[tblGrupaParametra].[Naziv]
  FROM dbo.[tblGrupaParametra]
 WHERE EXISTS (SELECT 1
                 FROM dbo.[tblGrupaDjelatnikParametra] 
                WHERE dbo.[tblGrupaDjelatnikParametra].[IDGrupaDjelatnik] = @IDGrupaDjelatnik
                  AND dbo.[tblGrupaDjelatnikParametra].[IDGrupaParemetra] = dbo.[tblGrupaParametra].[IDGrupaParametra]
                  )
				Select @@ROWCOUNT			
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaParametra_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaParametra_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaParametra_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblGrupaParametra table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaParametra_Find
(

	@SearchUsingOR bit   = null ,

	@IDGrupaParametra int   = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [IDGrupaParametra]
	, [Naziv]
    FROM
	[dbo].[tblGrupaParametra]
    WHERE 
	 ([IDGrupaParametra] = @IDGrupaParametra OR @IDGrupaParametra is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [IDGrupaParametra]
	, [Naziv]
    FROM
	[dbo].[tblGrupaParametra]
    WHERE 
	 ([IDGrupaParametra] = @IDGrupaParametra AND @IDGrupaParametra is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecDokTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecDokTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDokumentZaglavljeSpecDokTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTipOd],
					[IDDokumentTipZa]
				FROM
					[dbo].[tblDokumentZaglavljeSpecDokTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecDokTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecDokTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDokumentZaglavljeSpecDokTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDDokumentTipOd]'
				SET @SQL = @SQL + ', [IDDokumentTipZa]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentZaglavljeSpecDokTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDDokumentTipOd],'
				SET @SQL = @SQL + ' [IDDokumentTipZa]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentZaglavljeSpecDokTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecDokTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecDokTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDokumentZaglavljeSpecDokTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_Insert
(

	@ID int    OUTPUT,

	@IDDokumentTipOd int   ,

	@IDDokumentTipZa int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDokumentZaglavljeSpecDokTip]
					(
					[IDDokumentTipOd]
					,[IDDokumentTipZa]
					)
				VALUES
					(
					@IDDokumentTipOd
					,@IDDokumentTipZa
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecDokTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecDokTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDokumentZaglavljeSpecDokTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_Update
(

	@ID int   ,

	@IDDokumentTipOd int   ,

	@IDDokumentTipZa int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDokumentZaglavljeSpecDokTip]
				SET
					[IDDokumentTipOd] = @IDDokumentTipOd
					,[IDDokumentTipZa] = @IDDokumentTipZa
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecDokTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecDokTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDokumentZaglavljeSpecDokTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDokumentZaglavljeSpecDokTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecDokTip_GetByIDDokumentTipOd procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecDokTip_GetByIDDokumentTipOd') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_GetByIDDokumentTipOd
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentZaglavljeSpecDokTip table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_GetByIDDokumentTipOd
(

	@IDDokumentTipOd int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTipOd],
					[IDDokumentTipZa]
				FROM
					[dbo].[tblDokumentZaglavljeSpecDokTip]
				WHERE
					[IDDokumentTipOd] = @IDDokumentTipOd
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecDokTip_GetByIDDokumentTipZa procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecDokTip_GetByIDDokumentTipZa') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_GetByIDDokumentTipZa
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentZaglavljeSpecDokTip table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_GetByIDDokumentTipZa
(

	@IDDokumentTipZa int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokumentTipOd],
					[IDDokumentTipZa]
				FROM
					[dbo].[tblDokumentZaglavljeSpecDokTip]
				WHERE
					[IDDokumentTipZa] = @IDDokumentTipZa
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecDokTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecDokTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentZaglavljeSpecDokTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDDokumentTipOd],
					[IDDokumentTipZa]
				FROM
					[dbo].[tblDokumentZaglavljeSpecDokTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavljeSpecDokTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavljeSpecDokTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDokumentZaglavljeSpecDokTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavljeSpecDokTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDDokumentTipOd int   = null ,

	@IDDokumentTipZa int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDDokumentTipOd]
	, [IDDokumentTipZa]
    FROM
	[dbo].[tblDokumentZaglavljeSpecDokTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDDokumentTipOd] = @IDDokumentTipOd OR @IDDokumentTipOd is null)
	AND ([IDDokumentTipZa] = @IDDokumentTipZa OR @IDDokumentTipZa is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDDokumentTipOd]
	, [IDDokumentTipZa]
    FROM
	[dbo].[tblDokumentZaglavljeSpecDokTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDDokumentTipOd] = @IDDokumentTipOd AND @IDDokumentTipOd is not null)
	OR ([IDDokumentTipZa] = @IDDokumentTipZa AND @IDDokumentTipZa is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavlje_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavlje_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavlje_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDokumentZaglavlje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavlje_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokument],
					[IDSpecTip],
					[RedBr],
					[Kolona],
					[TekstZaglavlja],
					[FormatString],
					[FormatTip],
					[Vrijednost]
				FROM
					[dbo].[tblDokumentZaglavlje]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavlje_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavlje_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavlje_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDokumentZaglavlje table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavlje_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDDokument]'
				SET @SQL = @SQL + ', [IDSpecTip]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [Kolona]'
				SET @SQL = @SQL + ', [TekstZaglavlja]'
				SET @SQL = @SQL + ', [FormatString]'
				SET @SQL = @SQL + ', [FormatTip]'
				SET @SQL = @SQL + ', [Vrijednost]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentZaglavlje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDDokument],'
				SET @SQL = @SQL + ' [IDSpecTip],'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [Kolona],'
				SET @SQL = @SQL + ' [TekstZaglavlja],'
				SET @SQL = @SQL + ' [FormatString],'
				SET @SQL = @SQL + ' [FormatTip],'
				SET @SQL = @SQL + ' [Vrijednost]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDokumentZaglavlje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavlje_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavlje_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavlje_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDokumentZaglavlje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavlje_Insert
(

	@ID int    OUTPUT,

	@IDDokument int   ,

	@IDSpecTip int   ,

	@RedBr int   ,

	@Kolona money   ,

	@TekstZaglavlja nvarchar (100)  ,

	@FormatString nvarchar (250)  ,

	@FormatTip nvarchar (20)  ,

	@Vrijednost nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDokumentZaglavlje]
					(
					[IDDokument]
					,[IDSpecTip]
					,[RedBr]
					,[Kolona]
					,[TekstZaglavlja]
					,[FormatString]
					,[FormatTip]
					,[Vrijednost]
					)
				VALUES
					(
					@IDDokument
					,@IDSpecTip
					,@RedBr
					,@Kolona
					,@TekstZaglavlja
					,@FormatString
					,@FormatTip
					,@Vrijednost
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavlje_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavlje_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavlje_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDokumentZaglavlje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavlje_Update
(

	@ID int   ,

	@IDDokument int   ,

	@IDSpecTip int   ,

	@RedBr int   ,

	@Kolona money   ,

	@TekstZaglavlja nvarchar (100)  ,

	@FormatString nvarchar (250)  ,

	@FormatTip nvarchar (20)  ,

	@Vrijednost nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDokumentZaglavlje]
				SET
					[IDDokument] = @IDDokument
					,[IDSpecTip] = @IDSpecTip
					,[RedBr] = @RedBr
					,[Kolona] = @Kolona
					,[TekstZaglavlja] = @TekstZaglavlja
					,[FormatString] = @FormatString
					,[FormatTip] = @FormatTip
					,[Vrijednost] = @Vrijednost
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavlje_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavlje_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavlje_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDokumentZaglavlje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavlje_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDokumentZaglavlje] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavlje_GetByIDDokument procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavlje_GetByIDDokument') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavlje_GetByIDDokument
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentZaglavlje table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavlje_GetByIDDokument
(

	@IDDokument int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokument],
					[IDSpecTip],
					[RedBr],
					[Kolona],
					[TekstZaglavlja],
					[FormatString],
					[FormatTip],
					[Vrijednost]
				FROM
					[dbo].[tblDokumentZaglavlje]
				WHERE
					[IDDokument] = @IDDokument
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavlje_GetByIDSpecTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavlje_GetByIDSpecTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavlje_GetByIDSpecTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentZaglavlje table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavlje_GetByIDSpecTip
(

	@IDSpecTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDDokument],
					[IDSpecTip],
					[RedBr],
					[Kolona],
					[TekstZaglavlja],
					[FormatString],
					[FormatTip],
					[Vrijednost]
				FROM
					[dbo].[tblDokumentZaglavlje]
				WHERE
					[IDSpecTip] = @IDSpecTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavlje_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavlje_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavlje_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDokumentZaglavlje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavlje_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDDokument],
					[IDSpecTip],
					[RedBr],
					[Kolona],
					[TekstZaglavlja],
					[FormatString],
					[FormatTip],
					[Vrijednost]
				FROM
					[dbo].[tblDokumentZaglavlje]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDokumentZaglavlje_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDokumentZaglavlje_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDokumentZaglavlje_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDokumentZaglavlje table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDokumentZaglavlje_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDDokument int   = null ,

	@IDSpecTip int   = null ,

	@RedBr int   = null ,

	@Kolona money   = null ,

	@TekstZaglavlja nvarchar (100)  = null ,

	@FormatString nvarchar (250)  = null ,

	@FormatTip nvarchar (20)  = null ,

	@Vrijednost nvarchar (100)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDDokument]
	, [IDSpecTip]
	, [RedBr]
	, [Kolona]
	, [TekstZaglavlja]
	, [FormatString]
	, [FormatTip]
	, [Vrijednost]
    FROM
	[dbo].[tblDokumentZaglavlje]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDDokument] = @IDDokument OR @IDDokument is null)
	AND ([IDSpecTip] = @IDSpecTip OR @IDSpecTip is null)
	AND ([RedBr] = @RedBr OR @RedBr is null)
	AND ([Kolona] = @Kolona OR @Kolona is null)
	AND ([TekstZaglavlja] = @TekstZaglavlja OR @TekstZaglavlja is null)
	AND ([FormatString] = @FormatString OR @FormatString is null)
	AND ([FormatTip] = @FormatTip OR @FormatTip is null)
	AND ([Vrijednost] = @Vrijednost OR @Vrijednost is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDDokument]
	, [IDSpecTip]
	, [RedBr]
	, [Kolona]
	, [TekstZaglavlja]
	, [FormatString]
	, [FormatTip]
	, [Vrijednost]
    FROM
	[dbo].[tblDokumentZaglavlje]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDDokument] = @IDDokument AND @IDDokument is not null)
	OR ([IDSpecTip] = @IDSpecTip AND @IDSpecTip is not null)
	OR ([RedBr] = @RedBr AND @RedBr is not null)
	OR ([Kolona] = @Kolona AND @Kolona is not null)
	OR ([TekstZaglavlja] = @TekstZaglavlja AND @TekstZaglavlja is not null)
	OR ([FormatString] = @FormatString AND @FormatString is not null)
	OR ([FormatTip] = @FormatTip AND @FormatTip is not null)
	OR ([Vrijednost] = @Vrijednost AND @Vrijednost is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDefParametra_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDefParametra_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDefParametra_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblDefParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDefParametra_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Grupa],
					[Naziv]
				FROM
					[dbo].[tblDefParametra]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDefParametra_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDefParametra_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDefParametra_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblDefParametra table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDefParametra_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Grupa]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [dbo].[tblDefParametra]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Grupa],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblDefParametra]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDefParametra_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDefParametra_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDefParametra_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblDefParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDefParametra_Insert
(

	@ID int   ,

	@Grupa nvarchar (50)  ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblDefParametra]
					(
					[ID]
					,[Grupa]
					,[Naziv]
					)
				VALUES
					(
					@ID
					,@Grupa
					,@Naziv
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDefParametra_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDefParametra_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDefParametra_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblDefParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDefParametra_Update
(

	@ID int   ,

	@OriginalID int   ,

	@Grupa nvarchar (50)  ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblDefParametra]
				SET
					[ID] = @ID
					,[Grupa] = @Grupa
					,[Naziv] = @Naziv
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDefParametra_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDefParametra_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDefParametra_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblDefParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDefParametra_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblDefParametra] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDefParametra_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDefParametra_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDefParametra_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblDefParametra table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDefParametra_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Grupa],
					[Naziv]
				FROM
					[dbo].[tblDefParametra]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblDefParametra_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblDefParametra_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblDefParametra_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblDefParametra table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblDefParametra_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Grupa nvarchar (50)  = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Grupa]
	, [Naziv]
    FROM
	[dbo].[tblDefParametra]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Grupa] = @Grupa OR @Grupa is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Grupa]
	, [Naziv]
    FROM
	[dbo].[tblDefParametra]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Grupa] = @Grupa AND @Grupa is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblBlagdan_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblBlagdan_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblBlagdan_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblBlagdan table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblBlagdan_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[VrijediOd],
					[VrijediDo],
					[Datum],
					[SvakeGodine]
				FROM
					[pla].[tblBlagdan]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblBlagdan_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblBlagdan_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblBlagdan_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblBlagdan table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblBlagdan_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [VrijediOd]'
				SET @SQL = @SQL + ', [VrijediDo]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [SvakeGodine]'
				SET @SQL = @SQL + ' FROM [pla].[tblBlagdan]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [VrijediOd],'
				SET @SQL = @SQL + ' [VrijediDo],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [SvakeGodine]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblBlagdan]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblBlagdan_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblBlagdan_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblBlagdan_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblBlagdan table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblBlagdan_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (100)  ,

	@VrijediOd datetime   ,

	@VrijediDo datetime   ,

	@Datum datetime   ,

	@SvakeGodine bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblBlagdan]
					(
					[Naziv]
					,[VrijediOd]
					,[VrijediDo]
					,[Datum]
					,[SvakeGodine]
					)
				VALUES
					(
					@Naziv
					,@VrijediOd
					,@VrijediDo
					,@Datum
					,@SvakeGodine
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblBlagdan_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblBlagdan_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblBlagdan_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblBlagdan table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblBlagdan_Update
(

	@ID int   ,

	@Naziv nvarchar (100)  ,

	@VrijediOd datetime   ,

	@VrijediDo datetime   ,

	@Datum datetime   ,

	@SvakeGodine bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblBlagdan]
				SET
					[Naziv] = @Naziv
					,[VrijediOd] = @VrijediOd
					,[VrijediDo] = @VrijediDo
					,[Datum] = @Datum
					,[SvakeGodine] = @SvakeGodine
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblBlagdan_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblBlagdan_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblBlagdan_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblBlagdan table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblBlagdan_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblBlagdan] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblBlagdan_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblBlagdan_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblBlagdan_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagdan table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblBlagdan_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[VrijediOd],
					[VrijediDo],
					[Datum],
					[SvakeGodine]
				FROM
					[pla].[tblBlagdan]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblBlagdan_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblBlagdan_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblBlagdan_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblBlagdan table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblBlagdan_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (100)  = null ,

	@VrijediOd datetime   = null ,

	@VrijediDo datetime   = null ,

	@Datum datetime   = null ,

	@SvakeGodine bit   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [VrijediOd]
	, [VrijediDo]
	, [Datum]
	, [SvakeGodine]
    FROM
	[pla].[tblBlagdan]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([VrijediOd] = @VrijediOd OR @VrijediOd is null)
	AND ([VrijediDo] = @VrijediDo OR @VrijediDo is null)
	AND ([Datum] = @Datum OR @Datum is null)
	AND ([SvakeGodine] = @SvakeGodine OR @SvakeGodine is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [VrijediOd]
	, [VrijediDo]
	, [Datum]
	, [SvakeGodine]
    FROM
	[pla].[tblBlagdan]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([VrijediOd] = @VrijediOd AND @VrijediOd is not null)
	OR ([VrijediDo] = @VrijediDo AND @VrijediDo is not null)
	OR ([Datum] = @Datum AND @Datum is not null)
	OR ([SvakeGodine] = @SvakeGodine AND @SvakeGodine is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklMjera_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklMjera_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklMjera_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblArtiklMjera table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklMjera_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[SkraceniNaziv]
				FROM
					[dbo].[tblArtiklMjera]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklMjera_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklMjera_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklMjera_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblArtiklMjera table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklMjera_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [SkraceniNaziv]'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklMjera]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [SkraceniNaziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklMjera]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklMjera_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklMjera_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklMjera_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblArtiklMjera table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklMjera_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (200)  ,

	@SkraceniNaziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblArtiklMjera]
					(
					[Naziv]
					,[SkraceniNaziv]
					)
				VALUES
					(
					@Naziv
					,@SkraceniNaziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklMjera_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklMjera_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklMjera_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblArtiklMjera table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklMjera_Update
(

	@ID int   ,

	@Naziv nvarchar (200)  ,

	@SkraceniNaziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblArtiklMjera]
				SET
					[Naziv] = @Naziv
					,[SkraceniNaziv] = @SkraceniNaziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklMjera_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklMjera_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklMjera_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblArtiklMjera table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklMjera_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblArtiklMjera] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklMjera_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklMjera_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklMjera_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklMjera table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklMjera_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[SkraceniNaziv]
				FROM
					[dbo].[tblArtiklMjera]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklMjera_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklMjera_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklMjera_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblArtiklMjera table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklMjera_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (200)  = null ,

	@SkraceniNaziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [SkraceniNaziv]
    FROM
	[dbo].[tblArtiklMjera]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([SkraceniNaziv] = @SkraceniNaziv OR @SkraceniNaziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [SkraceniNaziv]
    FROM
	[dbo].[tblArtiklMjera]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([SkraceniNaziv] = @SkraceniNaziv AND @SkraceniNaziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklKategorija_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklKategorija_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklKategorija_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblArtiklKategorija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklKategorija_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[Abstraktna]
				FROM
					[dbo].[tblArtiklKategorija]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklKategorija_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklKategorija_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklKategorija_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblArtiklKategorija table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklKategorija_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [IDRoditelj]'
				SET @SQL = @SQL + ', [Hierarchy]'
				SET @SQL = @SQL + ', [Lvl]'
				SET @SQL = @SQL + ', [Abstraktna]'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklKategorija]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [IDRoditelj],'
				SET @SQL = @SQL + ' [Hierarchy],'
				SET @SQL = @SQL + ' [Lvl],'
				SET @SQL = @SQL + ' [Abstraktna]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklKategorija]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklKategorija_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklKategorija_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklKategorija_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblArtiklKategorija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklKategorija_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (200)  ,

	@IDRoditelj int   ,

	@Hierarchy nvarchar (200)  ,

	@Lvl int    OUTPUT,

	@Abstraktna bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblArtiklKategorija]
					(
					[Naziv]
					,[IDRoditelj]
					,[Hierarchy]
					,[Abstraktna]
					)
				VALUES
					(
					@Naziv
					,@IDRoditelj
					,@Hierarchy
					,@Abstraktna
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
				-- Select computed columns into output parameters
				SELECT
 @Lvl = [Lvl]
				FROM
					[dbo].[tblArtiklKategorija]
				WHERE
[ID] = @ID 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklKategorija_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklKategorija_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklKategorija_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblArtiklKategorija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklKategorija_Update
(

	@ID int   ,

	@Naziv nvarchar (200)  ,

	@IDRoditelj int   ,

	@Hierarchy nvarchar (200)  ,

	@Lvl int    OUTPUT,

	@Abstraktna bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblArtiklKategorija]
				SET
					[Naziv] = @Naziv
					,[IDRoditelj] = @IDRoditelj
					,[Hierarchy] = @Hierarchy
					,[Abstraktna] = @Abstraktna
				WHERE
[ID] = @ID 
				
				
				-- Select computed columns into output parameters
				SELECT
 @Lvl = [Lvl]
				FROM
					[dbo].[tblArtiklKategorija]
				WHERE
[ID] = @ID 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklKategorija_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklKategorija_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklKategorija_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblArtiklKategorija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklKategorija_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblArtiklKategorija] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklKategorija_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklKategorija_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklKategorija_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklKategorija table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklKategorija_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[IDRoditelj],
					[Hierarchy],
					[Lvl],
					[Abstraktna]
				FROM
					[dbo].[tblArtiklKategorija]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklKategorija_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklKategorija_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklKategorija_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblArtiklKategorija table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklKategorija_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (200)  = null ,

	@IDRoditelj int   = null ,

	@Hierarchy nvarchar (200)  = null ,

	@Lvl int   = null ,

	@Abstraktna bit   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [IDRoditelj]
	, [Hierarchy]
	, [Lvl]
	, [Abstraktna]
    FROM
	[dbo].[tblArtiklKategorija]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([IDRoditelj] = @IDRoditelj OR @IDRoditelj is null)
	AND ([Hierarchy] = @Hierarchy OR @Hierarchy is null)
	AND ([Lvl] = @Lvl OR @Lvl is null)
	AND ([Abstraktna] = @Abstraktna OR @Abstraktna is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [IDRoditelj]
	, [Hierarchy]
	, [Lvl]
	, [Abstraktna]
    FROM
	[dbo].[tblArtiklKategorija]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([IDRoditelj] = @IDRoditelj AND @IDRoditelj is not null)
	OR ([Hierarchy] = @Hierarchy AND @Hierarchy is not null)
	OR ([Lvl] = @Lvl AND @Lvl is not null)
	OR ([Abstraktna] = @Abstraktna AND @Abstraktna is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblArtikl table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblArtikl table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [BarCode]'
				SET @SQL = @SQL + ', [Kataloskibroj]'
				SET @SQL = @SQL + ', [OptimalnaKol]'
				SET @SQL = @SQL + ', [Slika]'
				SET @SQL = @SQL + ', [IDProizvodac]'
				SET @SQL = @SQL + ', [IDJedinicnaMjera]'
				SET @SQL = @SQL + ', [IDArtiklKategorija]'
				SET @SQL = @SQL + ', [IDPorez]'
				SET @SQL = @SQL + ', [Usluga]'
				SET @SQL = @SQL + ', [CijenaUsluge]'
				SET @SQL = @SQL + ', [IDArtiklStatus]'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtikl]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [BarCode],'
				SET @SQL = @SQL + ' [Kataloskibroj],'
				SET @SQL = @SQL + ' [OptimalnaKol],'
				SET @SQL = @SQL + ' [Slika],'
				SET @SQL = @SQL + ' [IDProizvodac],'
				SET @SQL = @SQL + ' [IDJedinicnaMjera],'
				SET @SQL = @SQL + ' [IDArtiklKategorija],'
				SET @SQL = @SQL + ' [IDPorez],'
				SET @SQL = @SQL + ' [Usluga],'
				SET @SQL = @SQL + ' [CijenaUsluge],'
				SET @SQL = @SQL + ' [IDArtiklStatus]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtikl]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblArtikl table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (200)  ,

	@BarCode nvarchar (50)  ,

	@Kataloskibroj varchar (50)  ,

	@OptimalnaKol real   ,

	@Slika image   ,

	@IDProizvodac int   ,

	@IDJedinicnaMjera int   ,

	@IDArtiklKategorija int   ,

	@IDPorez int   ,

	@Usluga int   ,

	@CijenaUsluge money   ,

	@IDArtiklStatus int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblArtikl]
					(
					[Naziv]
					,[BarCode]
					,[Kataloskibroj]
					,[OptimalnaKol]
					,[Slika]
					,[IDProizvodac]
					,[IDJedinicnaMjera]
					,[IDArtiklKategorija]
					,[IDPorez]
					,[Usluga]
					,[CijenaUsluge]
					,[IDArtiklStatus]
					)
				VALUES
					(
					@Naziv
					,@BarCode
					,@Kataloskibroj
					,@OptimalnaKol
					,@Slika
					,@IDProizvodac
					,@IDJedinicnaMjera
					,@IDArtiklKategorija
					,@IDPorez
					,@Usluga
					,@CijenaUsluge
					,@IDArtiklStatus
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblArtikl table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_Update
(

	@ID int   ,

	@Naziv nvarchar (200)  ,

	@BarCode nvarchar (50)  ,

	@Kataloskibroj varchar (50)  ,

	@OptimalnaKol real   ,

	@Slika image   ,

	@IDProizvodac int   ,

	@IDJedinicnaMjera int   ,

	@IDArtiklKategorija int   ,

	@IDPorez int   ,

	@Usluga int   ,

	@CijenaUsluge money   ,

	@IDArtiklStatus int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblArtikl]
				SET
					[Naziv] = @Naziv
					,[BarCode] = @BarCode
					,[Kataloskibroj] = @Kataloskibroj
					,[OptimalnaKol] = @OptimalnaKol
					,[Slika] = @Slika
					,[IDProizvodac] = @IDProizvodac
					,[IDJedinicnaMjera] = @IDJedinicnaMjera
					,[IDArtiklKategorija] = @IDArtiklKategorija
					,[IDPorez] = @IDPorez
					,[Usluga] = @Usluga
					,[CijenaUsluge] = @CijenaUsluge
					,[IDArtiklStatus] = @IDArtiklStatus
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblArtikl table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblArtikl] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByIDJedinicnaMjera procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByIDJedinicnaMjera') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByIDJedinicnaMjera
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByIDJedinicnaMjera
(

	@IDJedinicnaMjera int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[IDJedinicnaMjera] = @IDJedinicnaMjera
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByIDProizvodac procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByIDProizvodac') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByIDProizvodac
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByIDProizvodac
(

	@IDProizvodac int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[IDProizvodac] = @IDProizvodac
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByIDPorez procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByIDPorez') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByIDPorez
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByIDPorez
(

	@IDPorez int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[IDPorez] = @IDPorez
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByIDUsluga procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByIDUsluga') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByIDUsluga
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByIDUsluga
(

	@ID int   ,

	@Usluga int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[ID] = @ID
					AND [Usluga] = @Usluga
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByUsluga procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByUsluga') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByUsluga
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByUsluga
(

	@Usluga int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[Usluga] = @Usluga
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByIDPorezUslugaID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByIDPorezUslugaID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByIDPorezUslugaID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByIDPorezUslugaID
(

	@IDPorez int   ,

	@Usluga int   ,

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[IDPorez] = @IDPorez
					AND [Usluga] = @Usluga
					AND [ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByUslugaIDIDPorez procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByUslugaIDIDPorez') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByUslugaIDIDPorez
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByUslugaIDIDPorez
(

	@Usluga int   ,

	@ID int   ,

	@IDPorez int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[Usluga] = @Usluga
					AND [ID] = @ID
					AND [IDPorez] = @IDPorez
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByUslugaID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByUslugaID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByUslugaID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByUslugaID
(

	@Usluga int   ,

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[Usluga] = @Usluga
					AND [ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByIDArtiklKategorijaIDUslugaNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByIDArtiklKategorijaIDUslugaNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByIDArtiklKategorijaIDUslugaNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByIDArtiklKategorijaIDUslugaNaziv
(

	@IDArtiklKategorija int   ,

	@ID int   ,

	@Usluga int   ,

	@Naziv nvarchar (200)  
)
AS


				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[IDArtiklKategorija] = @IDArtiklKategorija
					AND [ID] = @ID
					AND [Usluga] = @Usluga
					AND [Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByIDArtiklKategorija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByIDArtiklKategorija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByIDArtiklKategorija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByIDArtiklKategorija
(

	@IDArtiklKategorija int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[IDArtiklKategorija] = @IDArtiklKategorija
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByNaziv
(

	@Naziv nvarchar (200)  
)
AS


				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_GetByIDArtiklStatus procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_GetByIDArtiklStatus') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_GetByIDArtiklStatus
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtikl table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_GetByIDArtiklStatus
(

	@IDArtiklStatus int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Kataloskibroj],
					[OptimalnaKol],
					[Slika],
					[IDProizvodac],
					[IDJedinicnaMjera],
					[IDArtiklKategorija],
					[IDPorez],
					[Usluga],
					[CijenaUsluge],
					[IDArtiklStatus]
				FROM
					[dbo].[tblArtikl]
				WHERE
					[IDArtiklStatus] = @IDArtiklStatus
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtikl_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtikl_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtikl_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblArtikl table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtikl_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (200)  = null ,

	@BarCode nvarchar (50)  = null ,

	@Kataloskibroj varchar (50)  = null ,

	@OptimalnaKol real   = null ,

	@Slika image   = null ,

	@IDProizvodac int   = null ,

	@IDJedinicnaMjera int   = null ,

	@IDArtiklKategorija int   = null ,

	@IDPorez int   = null ,

	@Usluga int   = null ,

	@CijenaUsluge money   = null ,

	@IDArtiklStatus int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [BarCode]
	, [Kataloskibroj]
	, [OptimalnaKol]
	, [Slika]
	, [IDProizvodac]
	, [IDJedinicnaMjera]
	, [IDArtiklKategorija]
	, [IDPorez]
	, [Usluga]
	, [CijenaUsluge]
	, [IDArtiklStatus]
    FROM
	[dbo].[tblArtikl]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([BarCode] = @BarCode OR @BarCode is null)
	AND ([Kataloskibroj] = @Kataloskibroj OR @Kataloskibroj is null)
	AND ([OptimalnaKol] = @OptimalnaKol OR @OptimalnaKol is null)
	AND ([IDProizvodac] = @IDProizvodac OR @IDProizvodac is null)
	AND ([IDJedinicnaMjera] = @IDJedinicnaMjera OR @IDJedinicnaMjera is null)
	AND ([IDArtiklKategorija] = @IDArtiklKategorija OR @IDArtiklKategorija is null)
	AND ([IDPorez] = @IDPorez OR @IDPorez is null)
	AND ([Usluga] = @Usluga OR @Usluga is null)
	AND ([CijenaUsluge] = @CijenaUsluge OR @CijenaUsluge is null)
	AND ([IDArtiklStatus] = @IDArtiklStatus OR @IDArtiklStatus is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [BarCode]
	, [Kataloskibroj]
	, [OptimalnaKol]
	, [Slika]
	, [IDProizvodac]
	, [IDJedinicnaMjera]
	, [IDArtiklKategorija]
	, [IDPorez]
	, [Usluga]
	, [CijenaUsluge]
	, [IDArtiklStatus]
    FROM
	[dbo].[tblArtikl]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([BarCode] = @BarCode AND @BarCode is not null)
	OR ([Kataloskibroj] = @Kataloskibroj AND @Kataloskibroj is not null)
	OR ([OptimalnaKol] = @OptimalnaKol AND @OptimalnaKol is not null)
	OR ([IDProizvodac] = @IDProizvodac AND @IDProizvodac is not null)
	OR ([IDJedinicnaMjera] = @IDJedinicnaMjera AND @IDJedinicnaMjera is not null)
	OR ([IDArtiklKategorija] = @IDArtiklKategorija AND @IDArtiklKategorija is not null)
	OR ([IDPorez] = @IDPorez AND @IDPorez is not null)
	OR ([Usluga] = @Usluga AND @Usluga is not null)
	OR ([CijenaUsluge] = @CijenaUsluge AND @CijenaUsluge is not null)
	OR ([IDArtiklStatus] = @IDArtiklStatus AND @IDArtiklStatus is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblAdresaTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblAdresaTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblAdresaTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblAdresaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblAdresaTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblAdresaTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblAdresaTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblAdresaTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblAdresaTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblAdresaTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblAdresaTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [pla].[tblAdresaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblAdresaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblAdresaTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblAdresaTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblAdresaTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblAdresaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblAdresaTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblAdresaTip]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblAdresaTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblAdresaTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblAdresaTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblAdresaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblAdresaTip_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblAdresaTip]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblAdresaTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblAdresaTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblAdresaTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblAdresaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblAdresaTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblAdresaTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblAdresaTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblAdresaTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblAdresaTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblAdresaTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblAdresaTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[pla].[tblAdresaTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblAdresaTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblAdresaTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblAdresaTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblAdresaTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblAdresaTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblAdresaTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[pla].[tblAdresaTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeServera_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeServera_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeServera_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tbl_PostavkeServera table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeServera_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Parametar],
					[ValueChar],
					[ValueInt],
					[ValueDate]
				FROM
					[dbo].[tbl_PostavkeServera]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeServera_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeServera_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeServera_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tbl_PostavkeServera table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeServera_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Parametar]'
				SET @SQL = @SQL + ', [ValueChar]'
				SET @SQL = @SQL + ', [ValueInt]'
				SET @SQL = @SQL + ', [ValueDate]'
				SET @SQL = @SQL + ' FROM [dbo].[tbl_PostavkeServera]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Parametar],'
				SET @SQL = @SQL + ' [ValueChar],'
				SET @SQL = @SQL + ' [ValueInt],'
				SET @SQL = @SQL + ' [ValueDate]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tbl_PostavkeServera]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeServera_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeServera_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeServera_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tbl_PostavkeServera table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeServera_Insert
(

	@ID int   ,

	@Parametar varchar (50)  ,

	@ValueChar nvarchar (50)  ,

	@ValueInt int   ,

	@ValueDate datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tbl_PostavkeServera]
					(
					[ID]
					,[Parametar]
					,[ValueChar]
					,[ValueInt]
					,[ValueDate]
					)
				VALUES
					(
					@ID
					,@Parametar
					,@ValueChar
					,@ValueInt
					,@ValueDate
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeServera_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeServera_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeServera_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tbl_PostavkeServera table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeServera_Update
(

	@ID int   ,

	@OriginalID int   ,

	@Parametar varchar (50)  ,

	@ValueChar nvarchar (50)  ,

	@ValueInt int   ,

	@ValueDate datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tbl_PostavkeServera]
				SET
					[ID] = @ID
					,[Parametar] = @Parametar
					,[ValueChar] = @ValueChar
					,[ValueInt] = @ValueInt
					,[ValueDate] = @ValueDate
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeServera_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeServera_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeServera_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tbl_PostavkeServera table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeServera_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tbl_PostavkeServera] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeServera_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeServera_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeServera_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tbl_PostavkeServera table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeServera_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Parametar],
					[ValueChar],
					[ValueInt],
					[ValueDate]
				FROM
					[dbo].[tbl_PostavkeServera]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tbl_PostavkeServera_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tbl_PostavkeServera_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tbl_PostavkeServera_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tbl_PostavkeServera table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tbl_PostavkeServera_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Parametar varchar (50)  = null ,

	@ValueChar nvarchar (50)  = null ,

	@ValueInt int   = null ,

	@ValueDate datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Parametar]
	, [ValueChar]
	, [ValueInt]
	, [ValueDate]
    FROM
	[dbo].[tbl_PostavkeServera]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Parametar] = @Parametar OR @Parametar is null)
	AND ([ValueChar] = @ValueChar OR @ValueChar is null)
	AND ([ValueInt] = @ValueInt OR @ValueInt is null)
	AND ([ValueDate] = @ValueDate OR @ValueDate is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Parametar]
	, [ValueChar]
	, [ValueInt]
	, [ValueDate]
    FROM
	[dbo].[tbl_PostavkeServera]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Parametar] = @Parametar AND @Parametar is not null)
	OR ([ValueChar] = @ValueChar AND @ValueChar is not null)
	OR ([ValueInt] = @ValueInt AND @ValueInt is not null)
	OR ([ValueDate] = @ValueDate AND @ValueDate is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblArtiklSpecifikacijaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblArtiklSpecifikacijaTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblArtiklSpecifikacijaTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklSpecifikacijaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklSpecifikacijaTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblArtiklSpecifikacijaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (10)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblArtiklSpecifikacijaTip]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblArtiklSpecifikacijaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaTip_Update
(

	@ID int   ,

	@Naziv nvarchar (10)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblArtiklSpecifikacijaTip]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblArtiklSpecifikacijaTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblArtiklSpecifikacijaTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaTip_GetByNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaTip_GetByNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaTip_GetByNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklSpecifikacijaTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaTip_GetByNaziv
(

	@Naziv nvarchar (10)  
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblArtiklSpecifikacijaTip]
				WHERE
					[Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklSpecifikacijaTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblArtiklSpecifikacijaTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblArtiklSpecifikacijaTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (10)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblArtiklSpecifikacijaTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblArtiklSpecifikacijaTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajna_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajna_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajna_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblBlagajna table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajna_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[PocetnoStanje],
					[IDOrganizacija],
					[IDKonto],
					[IDVrstaFinDokumenta],
					[PocetniBrojUplatnice],
					[PocetniBrojIsplatnice]
				FROM
					[fin].[tblBlagajna]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajna_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajna_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajna_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblBlagajna table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajna_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [PocetnoStanje]'
				SET @SQL = @SQL + ', [IDOrganizacija]'
				SET @SQL = @SQL + ', [IDKonto]'
				SET @SQL = @SQL + ', [IDVrstaFinDokumenta]'
				SET @SQL = @SQL + ', [PocetniBrojUplatnice]'
				SET @SQL = @SQL + ', [PocetniBrojIsplatnice]'
				SET @SQL = @SQL + ' FROM [fin].[tblBlagajna]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [PocetnoStanje],'
				SET @SQL = @SQL + ' [IDOrganizacija],'
				SET @SQL = @SQL + ' [IDKonto],'
				SET @SQL = @SQL + ' [IDVrstaFinDokumenta],'
				SET @SQL = @SQL + ' [PocetniBrojUplatnice],'
				SET @SQL = @SQL + ' [PocetniBrojIsplatnice]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblBlagajna]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajna_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajna_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajna_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblBlagajna table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajna_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (150)  ,

	@PocetnoStanje money   ,

	@IDOrganizacija int   ,

	@IDKonto int   ,

	@IDVrstaFinDokumenta int   ,

	@PocetniBrojUplatnice int   ,

	@PocetniBrojIsplatnice int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblBlagajna]
					(
					[Naziv]
					,[PocetnoStanje]
					,[IDOrganizacija]
					,[IDKonto]
					,[IDVrstaFinDokumenta]
					,[PocetniBrojUplatnice]
					,[PocetniBrojIsplatnice]
					)
				VALUES
					(
					@Naziv
					,@PocetnoStanje
					,@IDOrganizacija
					,@IDKonto
					,@IDVrstaFinDokumenta
					,@PocetniBrojUplatnice
					,@PocetniBrojIsplatnice
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajna_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajna_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajna_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblBlagajna table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajna_Update
(

	@ID int   ,

	@Naziv nvarchar (150)  ,

	@PocetnoStanje money   ,

	@IDOrganizacija int   ,

	@IDKonto int   ,

	@IDVrstaFinDokumenta int   ,

	@PocetniBrojUplatnice int   ,

	@PocetniBrojIsplatnice int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblBlagajna]
				SET
					[Naziv] = @Naziv
					,[PocetnoStanje] = @PocetnoStanje
					,[IDOrganizacija] = @IDOrganizacija
					,[IDKonto] = @IDKonto
					,[IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
					,[PocetniBrojUplatnice] = @PocetniBrojUplatnice
					,[PocetniBrojIsplatnice] = @PocetniBrojIsplatnice
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajna_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajna_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajna_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblBlagajna table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajna_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblBlagajna] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajna_GetByIDKonto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajna_GetByIDKonto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajna_GetByIDKonto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagajna table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajna_GetByIDKonto
(

	@IDKonto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[PocetnoStanje],
					[IDOrganizacija],
					[IDKonto],
					[IDVrstaFinDokumenta],
					[PocetniBrojUplatnice],
					[PocetniBrojIsplatnice]
				FROM
					[fin].[tblBlagajna]
				WHERE
					[IDKonto] = @IDKonto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajna_GetByIDOrganizacija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajna_GetByIDOrganizacija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajna_GetByIDOrganizacija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagajna table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajna_GetByIDOrganizacija
(

	@IDOrganizacija int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[PocetnoStanje],
					[IDOrganizacija],
					[IDKonto],
					[IDVrstaFinDokumenta],
					[PocetniBrojUplatnice],
					[PocetniBrojIsplatnice]
				FROM
					[fin].[tblBlagajna]
				WHERE
					[IDOrganizacija] = @IDOrganizacija
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajna_GetByIDVrstaFinDokumenta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajna_GetByIDVrstaFinDokumenta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajna_GetByIDVrstaFinDokumenta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagajna table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajna_GetByIDVrstaFinDokumenta
(

	@IDVrstaFinDokumenta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[PocetnoStanje],
					[IDOrganizacija],
					[IDKonto],
					[IDVrstaFinDokumenta],
					[PocetniBrojUplatnice],
					[PocetniBrojIsplatnice]
				FROM
					[fin].[tblBlagajna]
				WHERE
					[IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajna_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajna_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajna_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagajna table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajna_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[PocetnoStanje],
					[IDOrganizacija],
					[IDKonto],
					[IDVrstaFinDokumenta],
					[PocetniBrojUplatnice],
					[PocetniBrojIsplatnice]
				FROM
					[fin].[tblBlagajna]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajna_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajna_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajna_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblBlagajna table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajna_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (150)  = null ,

	@PocetnoStanje money   = null ,

	@IDOrganizacija int   = null ,

	@IDKonto int   = null ,

	@IDVrstaFinDokumenta int   = null ,

	@PocetniBrojUplatnice int   = null ,

	@PocetniBrojIsplatnice int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [PocetnoStanje]
	, [IDOrganizacija]
	, [IDKonto]
	, [IDVrstaFinDokumenta]
	, [PocetniBrojUplatnice]
	, [PocetniBrojIsplatnice]
    FROM
	[fin].[tblBlagajna]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([PocetnoStanje] = @PocetnoStanje OR @PocetnoStanje is null)
	AND ([IDOrganizacija] = @IDOrganizacija OR @IDOrganizacija is null)
	AND ([IDKonto] = @IDKonto OR @IDKonto is null)
	AND ([IDVrstaFinDokumenta] = @IDVrstaFinDokumenta OR @IDVrstaFinDokumenta is null)
	AND ([PocetniBrojUplatnice] = @PocetniBrojUplatnice OR @PocetniBrojUplatnice is null)
	AND ([PocetniBrojIsplatnice] = @PocetniBrojIsplatnice OR @PocetniBrojIsplatnice is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [PocetnoStanje]
	, [IDOrganizacija]
	, [IDKonto]
	, [IDVrstaFinDokumenta]
	, [PocetniBrojUplatnice]
	, [PocetniBrojIsplatnice]
    FROM
	[fin].[tblBlagajna]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([PocetnoStanje] = @PocetnoStanje AND @PocetnoStanje is not null)
	OR ([IDOrganizacija] = @IDOrganizacija AND @IDOrganizacija is not null)
	OR ([IDKonto] = @IDKonto AND @IDKonto is not null)
	OR ([IDVrstaFinDokumenta] = @IDVrstaFinDokumenta AND @IDVrstaFinDokumenta is not null)
	OR ([PocetniBrojUplatnice] = @PocetniBrojUplatnice AND @PocetniBrojUplatnice is not null)
	OR ([PocetniBrojIsplatnice] = @PocetniBrojIsplatnice AND @PocetniBrojIsplatnice is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklStatus_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklStatus_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklStatus_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblArtiklStatus table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklStatus_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblArtiklStatus]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklStatus_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklStatus_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklStatus_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblArtiklStatus table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklStatus_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklStatus]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklStatus]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklStatus_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklStatus_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklStatus_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblArtiklStatus table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklStatus_Insert
(

	@ID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblArtiklStatus]
					(
					[ID]
					,[Naziv]
					)
				VALUES
					(
					@ID
					,@Naziv
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklStatus_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklStatus_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklStatus_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblArtiklStatus table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklStatus_Update
(

	@ID int   ,

	@OriginalID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblArtiklStatus]
				SET
					[ID] = @ID
					,[Naziv] = @Naziv
				WHERE
[ID] = @OriginalID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklStatus_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklStatus_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklStatus_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblArtiklStatus table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklStatus_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblArtiklStatus] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklStatus_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklStatus_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklStatus_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklStatus table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklStatus_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblArtiklStatus]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklStatus_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklStatus_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklStatus_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblArtiklStatus table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklStatus_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblArtiklStatus]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblArtiklStatus]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaIzvjestaj_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaIzvjestaj_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaIzvjestaj_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblBlagajnaIzvjestaj table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaIzvjestaj_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[IDBlagajna],
					[IDUser],
					[IDKnjizenje]
				FROM
					[fin].[tblBlagajnaIzvjestaj]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaIzvjestaj_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaIzvjestaj_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaIzvjestaj_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblBlagajnaIzvjestaj table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaIzvjestaj_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [IDBlagajna]'
				SET @SQL = @SQL + ', [IDUser]'
				SET @SQL = @SQL + ', [IDKnjizenje]'
				SET @SQL = @SQL + ' FROM [fin].[tblBlagajnaIzvjestaj]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [IDBlagajna],'
				SET @SQL = @SQL + ' [IDUser],'
				SET @SQL = @SQL + ' [IDKnjizenje]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblBlagajnaIzvjestaj]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaIzvjestaj_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaIzvjestaj_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaIzvjestaj_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblBlagajnaIzvjestaj table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaIzvjestaj_Insert
(

	@ID int    OUTPUT,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@IDBlagajna int   ,

	@IDUser int   ,

	@IDKnjizenje int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblBlagajnaIzvjestaj]
					(
					[DatumOd]
					,[DatumDo]
					,[IDBlagajna]
					,[IDUser]
					,[IDKnjizenje]
					)
				VALUES
					(
					@DatumOd
					,@DatumDo
					,@IDBlagajna
					,@IDUser
					,@IDKnjizenje
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaIzvjestaj_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaIzvjestaj_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaIzvjestaj_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblBlagajnaIzvjestaj table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaIzvjestaj_Update
(

	@ID int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@IDBlagajna int   ,

	@IDUser int   ,

	@IDKnjizenje int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblBlagajnaIzvjestaj]
				SET
					[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[IDBlagajna] = @IDBlagajna
					,[IDUser] = @IDUser
					,[IDKnjizenje] = @IDKnjizenje
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaIzvjestaj_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaIzvjestaj_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaIzvjestaj_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblBlagajnaIzvjestaj table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaIzvjestaj_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblBlagajnaIzvjestaj] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaIzvjestaj_GetByIDBlagajna procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaIzvjestaj_GetByIDBlagajna') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaIzvjestaj_GetByIDBlagajna
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagajnaIzvjestaj table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaIzvjestaj_GetByIDBlagajna
(

	@IDBlagajna int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[IDBlagajna],
					[IDUser],
					[IDKnjizenje]
				FROM
					[fin].[tblBlagajnaIzvjestaj]
				WHERE
					[IDBlagajna] = @IDBlagajna
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaIzvjestaj_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaIzvjestaj_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaIzvjestaj_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagajnaIzvjestaj table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaIzvjestaj_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[IDBlagajna],
					[IDUser],
					[IDKnjizenje]
				FROM
					[fin].[tblBlagajnaIzvjestaj]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaIzvjestaj_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaIzvjestaj_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaIzvjestaj_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblBlagajnaIzvjestaj table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaIzvjestaj_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@IDBlagajna int   = null ,

	@IDUser int   = null ,

	@IDKnjizenje int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [DatumOd]
	, [DatumDo]
	, [IDBlagajna]
	, [IDUser]
	, [IDKnjizenje]
    FROM
	[fin].[tblBlagajnaIzvjestaj]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([IDBlagajna] = @IDBlagajna OR @IDBlagajna is null)
	AND ([IDUser] = @IDUser OR @IDUser is null)
	AND ([IDKnjizenje] = @IDKnjizenje OR @IDKnjizenje is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [DatumOd]
	, [DatumDo]
	, [IDBlagajna]
	, [IDUser]
	, [IDKnjizenje]
    FROM
	[fin].[tblBlagajnaIzvjestaj]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([IDBlagajna] = @IDBlagajna AND @IDBlagajna is not null)
	OR ([IDUser] = @IDUser AND @IDUser is not null)
	OR ([IDKnjizenje] = @IDKnjizenje AND @IDKnjizenje is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaStavka_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaStavka_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaStavka_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblBlagajnaStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaStavka_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDBlagajnaIzvjestaj],
					[DatumDokumenta],
					[Ulaz],
					[Izlaz],
					[DateUICreated],
					[Opis],
					[IDKonto],
					[Primatelj],
					[IDOrganizacija],
					[TipStavke],
					[IDKlijent]
				FROM
					[fin].[tblBlagajnaStavka]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaStavka_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaStavka_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaStavka_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblBlagajnaStavka table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaStavka_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDBlagajnaIzvjestaj]'
				SET @SQL = @SQL + ', [DatumDokumenta]'
				SET @SQL = @SQL + ', [Ulaz]'
				SET @SQL = @SQL + ', [Izlaz]'
				SET @SQL = @SQL + ', [DateUICreated]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [IDKonto]'
				SET @SQL = @SQL + ', [Primatelj]'
				SET @SQL = @SQL + ', [IDOrganizacija]'
				SET @SQL = @SQL + ', [TipStavke]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ' FROM [fin].[tblBlagajnaStavka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDBlagajnaIzvjestaj],'
				SET @SQL = @SQL + ' [DatumDokumenta],'
				SET @SQL = @SQL + ' [Ulaz],'
				SET @SQL = @SQL + ' [Izlaz],'
				SET @SQL = @SQL + ' [DateUICreated],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [IDKonto],'
				SET @SQL = @SQL + ' [Primatelj],'
				SET @SQL = @SQL + ' [IDOrganizacija],'
				SET @SQL = @SQL + ' [TipStavke],'
				SET @SQL = @SQL + ' [IDKlijent]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblBlagajnaStavka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaStavka_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaStavka_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaStavka_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblBlagajnaStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaStavka_Insert
(

	@ID int    OUTPUT,

	@IDBlagajnaIzvjestaj int   ,

	@DatumDokumenta datetime   ,

	@Ulaz money   ,

	@Izlaz money   ,

	@DateUICreated datetime   ,

	@Opis nvarchar (200)  ,

	@IDKonto int   ,

	@Primatelj nvarchar (50)  ,

	@IDOrganizacija int   ,

	@TipStavke int    OUTPUT,

	@IDKlijent int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblBlagajnaStavka]
					(
					[IDBlagajnaIzvjestaj]
					,[DatumDokumenta]
					,[Ulaz]
					,[Izlaz]
					,[DateUICreated]
					,[Opis]
					,[IDKonto]
					,[Primatelj]
					,[IDOrganizacija]
					,[IDKlijent]
					)
				VALUES
					(
					@IDBlagajnaIzvjestaj
					,@DatumDokumenta
					,@Ulaz
					,@Izlaz
					,@DateUICreated
					,@Opis
					,@IDKonto
					,@Primatelj
					,@IDOrganizacija
					,@IDKlijent
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
				-- Select computed columns into output parameters
				SELECT
 @TipStavke = [TipStavke]
				FROM
					[fin].[tblBlagajnaStavka]
				WHERE
[ID] = @ID 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaStavka_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaStavka_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaStavka_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblBlagajnaStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaStavka_Update
(

	@ID int   ,

	@IDBlagajnaIzvjestaj int   ,

	@DatumDokumenta datetime   ,

	@Ulaz money   ,

	@Izlaz money   ,

	@DateUICreated datetime   ,

	@Opis nvarchar (200)  ,

	@IDKonto int   ,

	@Primatelj nvarchar (50)  ,

	@IDOrganizacija int   ,

	@TipStavke int    OUTPUT,

	@IDKlijent int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblBlagajnaStavka]
				SET
					[IDBlagajnaIzvjestaj] = @IDBlagajnaIzvjestaj
					,[DatumDokumenta] = @DatumDokumenta
					,[Ulaz] = @Ulaz
					,[Izlaz] = @Izlaz
					,[DateUICreated] = @DateUICreated
					,[Opis] = @Opis
					,[IDKonto] = @IDKonto
					,[Primatelj] = @Primatelj
					,[IDOrganizacija] = @IDOrganizacija
					,[IDKlijent] = @IDKlijent
				WHERE
[ID] = @ID 
				
				
				-- Select computed columns into output parameters
				SELECT
 @TipStavke = [TipStavke]
				FROM
					[fin].[tblBlagajnaStavka]
				WHERE
[ID] = @ID 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaStavka_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaStavka_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaStavka_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblBlagajnaStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaStavka_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblBlagajnaStavka] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaStavka_GetByIDBlagajnaIzvjestaj procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaStavka_GetByIDBlagajnaIzvjestaj') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaStavka_GetByIDBlagajnaIzvjestaj
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagajnaStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaStavka_GetByIDBlagajnaIzvjestaj
(

	@IDBlagajnaIzvjestaj int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDBlagajnaIzvjestaj],
					[DatumDokumenta],
					[Ulaz],
					[Izlaz],
					[DateUICreated],
					[Opis],
					[IDKonto],
					[Primatelj],
					[IDOrganizacija],
					[TipStavke],
					[IDKlijent]
				FROM
					[fin].[tblBlagajnaStavka]
				WHERE
					[IDBlagajnaIzvjestaj] = @IDBlagajnaIzvjestaj
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaStavka_GetByIDKlijent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaStavka_GetByIDKlijent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaStavka_GetByIDKlijent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagajnaStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaStavka_GetByIDKlijent
(

	@IDKlijent int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDBlagajnaIzvjestaj],
					[DatumDokumenta],
					[Ulaz],
					[Izlaz],
					[DateUICreated],
					[Opis],
					[IDKonto],
					[Primatelj],
					[IDOrganizacija],
					[TipStavke],
					[IDKlijent]
				FROM
					[fin].[tblBlagajnaStavka]
				WHERE
					[IDKlijent] = @IDKlijent
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaStavka_GetByIDKonto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaStavka_GetByIDKonto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaStavka_GetByIDKonto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagajnaStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaStavka_GetByIDKonto
(

	@IDKonto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDBlagajnaIzvjestaj],
					[DatumDokumenta],
					[Ulaz],
					[Izlaz],
					[DateUICreated],
					[Opis],
					[IDKonto],
					[Primatelj],
					[IDOrganizacija],
					[TipStavke],
					[IDKlijent]
				FROM
					[fin].[tblBlagajnaStavka]
				WHERE
					[IDKonto] = @IDKonto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaStavka_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaStavka_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaStavka_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBlagajnaStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaStavka_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDBlagajnaIzvjestaj],
					[DatumDokumenta],
					[Ulaz],
					[Izlaz],
					[DateUICreated],
					[Opis],
					[IDKonto],
					[Primatelj],
					[IDOrganizacija],
					[TipStavke],
					[IDKlijent]
				FROM
					[fin].[tblBlagajnaStavka]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblBlagajnaStavka_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblBlagajnaStavka_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblBlagajnaStavka_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblBlagajnaStavka table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblBlagajnaStavka_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDBlagajnaIzvjestaj int   = null ,

	@DatumDokumenta datetime   = null ,

	@Ulaz money   = null ,

	@Izlaz money   = null ,

	@DateUICreated datetime   = null ,

	@Opis nvarchar (200)  = null ,

	@IDKonto int   = null ,

	@Primatelj nvarchar (50)  = null ,

	@IDOrganizacija int   = null ,

	@TipStavke int   = null ,

	@IDKlijent int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDBlagajnaIzvjestaj]
	, [DatumDokumenta]
	, [Ulaz]
	, [Izlaz]
	, [DateUICreated]
	, [Opis]
	, [IDKonto]
	, [Primatelj]
	, [IDOrganizacija]
	, [TipStavke]
	, [IDKlijent]
    FROM
	[fin].[tblBlagajnaStavka]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDBlagajnaIzvjestaj] = @IDBlagajnaIzvjestaj OR @IDBlagajnaIzvjestaj is null)
	AND ([DatumDokumenta] = @DatumDokumenta OR @DatumDokumenta is null)
	AND ([Ulaz] = @Ulaz OR @Ulaz is null)
	AND ([Izlaz] = @Izlaz OR @Izlaz is null)
	AND ([DateUICreated] = @DateUICreated OR @DateUICreated is null)
	AND ([Opis] = @Opis OR @Opis is null)
	AND ([IDKonto] = @IDKonto OR @IDKonto is null)
	AND ([Primatelj] = @Primatelj OR @Primatelj is null)
	AND ([IDOrganizacija] = @IDOrganizacija OR @IDOrganizacija is null)
	AND ([TipStavke] = @TipStavke OR @TipStavke is null)
	AND ([IDKlijent] = @IDKlijent OR @IDKlijent is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDBlagajnaIzvjestaj]
	, [DatumDokumenta]
	, [Ulaz]
	, [Izlaz]
	, [DateUICreated]
	, [Opis]
	, [IDKonto]
	, [Primatelj]
	, [IDOrganizacija]
	, [TipStavke]
	, [IDKlijent]
    FROM
	[fin].[tblBlagajnaStavka]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDBlagajnaIzvjestaj] = @IDBlagajnaIzvjestaj AND @IDBlagajnaIzvjestaj is not null)
	OR ([DatumDokumenta] = @DatumDokumenta AND @DatumDokumenta is not null)
	OR ([Ulaz] = @Ulaz AND @Ulaz is not null)
	OR ([Izlaz] = @Izlaz AND @Izlaz is not null)
	OR ([DateUICreated] = @DateUICreated AND @DateUICreated is not null)
	OR ([Opis] = @Opis AND @Opis is not null)
	OR ([IDKonto] = @IDKonto AND @IDKonto is not null)
	OR ([Primatelj] = @Primatelj AND @Primatelj is not null)
	OR ([IDOrganizacija] = @IDOrganizacija AND @IDOrganizacija is not null)
	OR ([TipStavke] = @TipStavke AND @TipStavke is not null)
	OR ([IDKlijent] = @IDKlijent AND @IDKlijent is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblBanka_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblBanka_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblBanka_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblBanka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblBanka_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[VodeciBrojDepozitneIstitucije],
					[IDMjesto],
					[MB],
					[MinimalniIznos],
					[MaksimalniIznos],
					[MaksimalniBrojRata]
				FROM
					[dbo].[tblBanka]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblBanka_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblBanka_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblBanka_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblBanka table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblBanka_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [VodeciBrojDepozitneIstitucije]'
				SET @SQL = @SQL + ', [IDMjesto]'
				SET @SQL = @SQL + ', [MB]'
				SET @SQL = @SQL + ', [MinimalniIznos]'
				SET @SQL = @SQL + ', [MaksimalniIznos]'
				SET @SQL = @SQL + ', [MaksimalniBrojRata]'
				SET @SQL = @SQL + ' FROM [dbo].[tblBanka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [VodeciBrojDepozitneIstitucije],'
				SET @SQL = @SQL + ' [IDMjesto],'
				SET @SQL = @SQL + ' [MB],'
				SET @SQL = @SQL + ' [MinimalniIznos],'
				SET @SQL = @SQL + ' [MaksimalniIznos],'
				SET @SQL = @SQL + ' [MaksimalniBrojRata]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblBanka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblBanka_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblBanka_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblBanka_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblBanka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblBanka_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (200)  ,

	@VodeciBrojDepozitneIstitucije int   ,

	@IDMjesto int   ,

	@MB nvarchar (50)  ,

	@MinimalniIznos money   ,

	@MaksimalniIznos money   ,

	@MaksimalniBrojRata int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblBanka]
					(
					[Naziv]
					,[VodeciBrojDepozitneIstitucije]
					,[IDMjesto]
					,[MB]
					,[MinimalniIznos]
					,[MaksimalniIznos]
					,[MaksimalniBrojRata]
					)
				VALUES
					(
					@Naziv
					,@VodeciBrojDepozitneIstitucije
					,@IDMjesto
					,@MB
					,@MinimalniIznos
					,@MaksimalniIznos
					,@MaksimalniBrojRata
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblBanka_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblBanka_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblBanka_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblBanka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblBanka_Update
(

	@ID int   ,

	@Naziv nvarchar (200)  ,

	@VodeciBrojDepozitneIstitucije int   ,

	@IDMjesto int   ,

	@MB nvarchar (50)  ,

	@MinimalniIznos money   ,

	@MaksimalniIznos money   ,

	@MaksimalniBrojRata int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblBanka]
				SET
					[Naziv] = @Naziv
					,[VodeciBrojDepozitneIstitucije] = @VodeciBrojDepozitneIstitucije
					,[IDMjesto] = @IDMjesto
					,[MB] = @MB
					,[MinimalniIznos] = @MinimalniIznos
					,[MaksimalniIznos] = @MaksimalniIznos
					,[MaksimalniBrojRata] = @MaksimalniBrojRata
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblBanka_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblBanka_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblBanka_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblBanka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblBanka_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblBanka] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblBanka_GetByIDMjesto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblBanka_GetByIDMjesto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblBanka_GetByIDMjesto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBanka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblBanka_GetByIDMjesto
(

	@IDMjesto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[VodeciBrojDepozitneIstitucije],
					[IDMjesto],
					[MB],
					[MinimalniIznos],
					[MaksimalniIznos],
					[MaksimalniBrojRata]
				FROM
					[dbo].[tblBanka]
				WHERE
					[IDMjesto] = @IDMjesto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblBanka_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblBanka_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblBanka_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblBanka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblBanka_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[VodeciBrojDepozitneIstitucije],
					[IDMjesto],
					[MB],
					[MinimalniIznos],
					[MaksimalniIznos],
					[MaksimalniBrojRata]
				FROM
					[dbo].[tblBanka]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblBanka_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblBanka_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblBanka_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblBanka table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblBanka_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (200)  = null ,

	@VodeciBrojDepozitneIstitucije int   = null ,

	@IDMjesto int   = null ,

	@MB nvarchar (50)  = null ,

	@MinimalniIznos money   = null ,

	@MaksimalniIznos money   = null ,

	@MaksimalniBrojRata int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [VodeciBrojDepozitneIstitucije]
	, [IDMjesto]
	, [MB]
	, [MinimalniIznos]
	, [MaksimalniIznos]
	, [MaksimalniBrojRata]
    FROM
	[dbo].[tblBanka]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([VodeciBrojDepozitneIstitucije] = @VodeciBrojDepozitneIstitucije OR @VodeciBrojDepozitneIstitucije is null)
	AND ([IDMjesto] = @IDMjesto OR @IDMjesto is null)
	AND ([MB] = @MB OR @MB is null)
	AND ([MinimalniIznos] = @MinimalniIznos OR @MinimalniIznos is null)
	AND ([MaksimalniIznos] = @MaksimalniIznos OR @MaksimalniIznos is null)
	AND ([MaksimalniBrojRata] = @MaksimalniBrojRata OR @MaksimalniBrojRata is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [VodeciBrojDepozitneIstitucije]
	, [IDMjesto]
	, [MB]
	, [MinimalniIznos]
	, [MaksimalniIznos]
	, [MaksimalniBrojRata]
    FROM
	[dbo].[tblBanka]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([VodeciBrojDepozitneIstitucije] = @VodeciBrojDepozitneIstitucije AND @VodeciBrojDepozitneIstitucije is not null)
	OR ([IDMjesto] = @IDMjesto AND @IDMjesto is not null)
	OR ([MB] = @MB AND @MB is not null)
	OR ([MinimalniIznos] = @MinimalniIznos AND @MinimalniIznos is not null)
	OR ([MaksimalniIznos] = @MaksimalniIznos AND @MaksimalniIznos is not null)
	OR ([MaksimalniBrojRata] = @MaksimalniBrojRata AND @MaksimalniBrojRata is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacija_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacija_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacija_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblArtiklSpecifikacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacija_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDTip],
					[IDKategorija],
					[RedBrRacunu],
					[FormatPrikaza]
				FROM
					[dbo].[tblArtiklSpecifikacija]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacija_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacija_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacija_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblArtiklSpecifikacija table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacija_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [IDTip]'
				SET @SQL = @SQL + ', [IDKategorija]'
				SET @SQL = @SQL + ', [RedBrRacunu]'
				SET @SQL = @SQL + ', [FormatPrikaza]'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklSpecifikacija]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [IDTip],'
				SET @SQL = @SQL + ' [IDKategorija],'
				SET @SQL = @SQL + ' [RedBrRacunu],'
				SET @SQL = @SQL + ' [FormatPrikaza]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklSpecifikacija]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacija_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacija_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacija_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblArtiklSpecifikacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacija_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (200)  ,

	@IDTip int   ,

	@IDKategorija int   ,

	@RedBrRacunu int   ,

	@FormatPrikaza nvarchar (150)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblArtiklSpecifikacija]
					(
					[Naziv]
					,[IDTip]
					,[IDKategorija]
					,[RedBrRacunu]
					,[FormatPrikaza]
					)
				VALUES
					(
					@Naziv
					,@IDTip
					,@IDKategorija
					,@RedBrRacunu
					,@FormatPrikaza
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacija_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacija_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacija_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblArtiklSpecifikacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacija_Update
(

	@ID int   ,

	@Naziv nvarchar (200)  ,

	@IDTip int   ,

	@IDKategorija int   ,

	@RedBrRacunu int   ,

	@FormatPrikaza nvarchar (150)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblArtiklSpecifikacija]
				SET
					[Naziv] = @Naziv
					,[IDTip] = @IDTip
					,[IDKategorija] = @IDKategorija
					,[RedBrRacunu] = @RedBrRacunu
					,[FormatPrikaza] = @FormatPrikaza
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacija_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacija_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacija_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblArtiklSpecifikacija table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacija_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblArtiklSpecifikacija] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacija_GetByIDKategorija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacija_GetByIDKategorija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacija_GetByIDKategorija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklSpecifikacija table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacija_GetByIDKategorija
(

	@IDKategorija int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDTip],
					[IDKategorija],
					[RedBrRacunu],
					[FormatPrikaza]
				FROM
					[dbo].[tblArtiklSpecifikacija]
				WHERE
					[IDKategorija] = @IDKategorija
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacija_GetByIDTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacija_GetByIDTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacija_GetByIDTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklSpecifikacija table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacija_GetByIDTip
(

	@IDTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDTip],
					[IDKategorija],
					[RedBrRacunu],
					[FormatPrikaza]
				FROM
					[dbo].[tblArtiklSpecifikacija]
				WHERE
					[IDTip] = @IDTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacija_GetByNazivIDKategorija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacija_GetByNazivIDKategorija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacija_GetByNazivIDKategorija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklSpecifikacija table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacija_GetByNazivIDKategorija
(

	@Naziv nvarchar (200)  ,

	@IDKategorija int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[IDTip],
					[IDKategorija],
					[RedBrRacunu],
					[FormatPrikaza]
				FROM
					[dbo].[tblArtiklSpecifikacija]
				WHERE
					[Naziv] = @Naziv
					AND [IDKategorija] = @IDKategorija
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacija_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacija_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacija_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklSpecifikacija table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacija_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[IDTip],
					[IDKategorija],
					[RedBrRacunu],
					[FormatPrikaza]
				FROM
					[dbo].[tblArtiklSpecifikacija]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacija_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacija_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacija_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblArtiklSpecifikacija table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacija_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (200)  = null ,

	@IDTip int   = null ,

	@IDKategorija int   = null ,

	@RedBrRacunu int   = null ,

	@FormatPrikaza nvarchar (150)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [IDTip]
	, [IDKategorija]
	, [RedBrRacunu]
	, [FormatPrikaza]
    FROM
	[dbo].[tblArtiklSpecifikacija]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([IDTip] = @IDTip OR @IDTip is null)
	AND ([IDKategorija] = @IDKategorija OR @IDKategorija is null)
	AND ([RedBrRacunu] = @RedBrRacunu OR @RedBrRacunu is null)
	AND ([FormatPrikaza] = @FormatPrikaza OR @FormatPrikaza is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [IDTip]
	, [IDKategorija]
	, [RedBrRacunu]
	, [FormatPrikaza]
    FROM
	[dbo].[tblArtiklSpecifikacija]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([IDTip] = @IDTip AND @IDTip is not null)
	OR ([IDKategorija] = @IDKategorija AND @IDKategorija is not null)
	OR ([RedBrRacunu] = @RedBrRacunu AND @RedBrRacunu is not null)
	OR ([FormatPrikaza] = @FormatPrikaza AND @FormatPrikaza is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnik_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnik_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnik_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblGrupaDjelatnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnik_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[RestrikcijaDatuma],
					[RestrikcijaNC]
				FROM
					[dbo].[tblGrupaDjelatnik]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnik_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnik_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnik_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblGrupaDjelatnik table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnik_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [RestrikcijaDatuma]'
				SET @SQL = @SQL + ', [RestrikcijaNC]'
				SET @SQL = @SQL + ' FROM [dbo].[tblGrupaDjelatnik]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [RestrikcijaDatuma],'
				SET @SQL = @SQL + ' [RestrikcijaNC]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblGrupaDjelatnik]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnik_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnik_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnik_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblGrupaDjelatnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnik_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (100)  ,

	@RestrikcijaDatuma bit   ,

	@RestrikcijaNC bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblGrupaDjelatnik]
					(
					[Naziv]
					,[RestrikcijaDatuma]
					,[RestrikcijaNC]
					)
				VALUES
					(
					@Naziv
					,@RestrikcijaDatuma
					,@RestrikcijaNC
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnik_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnik_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnik_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblGrupaDjelatnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnik_Update
(

	@ID int   ,

	@Naziv nvarchar (100)  ,

	@RestrikcijaDatuma bit   ,

	@RestrikcijaNC bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblGrupaDjelatnik]
				SET
					[Naziv] = @Naziv
					,[RestrikcijaDatuma] = @RestrikcijaDatuma
					,[RestrikcijaNC] = @RestrikcijaNC
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnik_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnik_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnik_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblGrupaDjelatnik table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnik_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblGrupaDjelatnik] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnik_GetByNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnik_GetByNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnik_GetByNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDjelatnik table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnik_GetByNaziv
(

	@Naziv nvarchar (100)  
)
AS


				SELECT
					[ID],
					[Naziv],
					[RestrikcijaDatuma],
					[RestrikcijaNC]
				FROM
					[dbo].[tblGrupaDjelatnik]
				WHERE
					[Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnik_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnik_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnik_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDjelatnik table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnik_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[RestrikcijaDatuma],
					[RestrikcijaNC]
				FROM
					[dbo].[tblGrupaDjelatnik]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnik_GetByIDDjelatnikFromDjelatnikInGrupa procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnik_GetByIDDjelatnikFromDjelatnikInGrupa') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnik_GetByIDDjelatnikFromDjelatnikInGrupa
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records through a junction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnik_GetByIDDjelatnikFromDjelatnikInGrupa
(

	@IDDjelatnik int   
)
AS


SELECT dbo.[tblGrupaDjelatnik].[ID]
       ,dbo.[tblGrupaDjelatnik].[Naziv]
       ,dbo.[tblGrupaDjelatnik].[RestrikcijaDatuma]
       ,dbo.[tblGrupaDjelatnik].[RestrikcijaNC]
  FROM dbo.[tblGrupaDjelatnik]
 WHERE EXISTS (SELECT 1
                 FROM dbo.[tblDjelatnikInGrupa] 
                WHERE dbo.[tblDjelatnikInGrupa].[IDDjelatnik] = @IDDjelatnik
                  AND dbo.[tblDjelatnikInGrupa].[IDGrupaDjelatnik] = dbo.[tblGrupaDjelatnik].[ID]
                  )
				Select @@ROWCOUNT			
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnik_GetByIDGrupaParemetraFromGrupaDjelatnikParametra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnik_GetByIDGrupaParemetraFromGrupaDjelatnikParametra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnik_GetByIDGrupaParemetraFromGrupaDjelatnikParametra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records through a junction table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnik_GetByIDGrupaParemetraFromGrupaDjelatnikParametra
(

	@IDGrupaParemetra int   
)
AS


SELECT dbo.[tblGrupaDjelatnik].[ID]
       ,dbo.[tblGrupaDjelatnik].[Naziv]
       ,dbo.[tblGrupaDjelatnik].[RestrikcijaDatuma]
       ,dbo.[tblGrupaDjelatnik].[RestrikcijaNC]
  FROM dbo.[tblGrupaDjelatnik]
 WHERE EXISTS (SELECT 1
                 FROM dbo.[tblGrupaDjelatnikParametra] 
                WHERE dbo.[tblGrupaDjelatnikParametra].[IDGrupaParemetra] = @IDGrupaParemetra
                  AND dbo.[tblGrupaDjelatnikParametra].[IDGrupaDjelatnik] = dbo.[tblGrupaDjelatnik].[ID]
                  )
				Select @@ROWCOUNT			
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnik_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnik_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnik_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblGrupaDjelatnik table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnik_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (100)  = null ,

	@RestrikcijaDatuma bit   = null ,

	@RestrikcijaNC bit   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [RestrikcijaDatuma]
	, [RestrikcijaNC]
    FROM
	[dbo].[tblGrupaDjelatnik]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([RestrikcijaDatuma] = @RestrikcijaDatuma OR @RestrikcijaDatuma is null)
	AND ([RestrikcijaNC] = @RestrikcijaNC OR @RestrikcijaNC is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [RestrikcijaDatuma]
	, [RestrikcijaNC]
    FROM
	[dbo].[tblGrupaDjelatnik]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([RestrikcijaDatuma] = @RestrikcijaDatuma AND @RestrikcijaDatuma is not null)
	OR ([RestrikcijaNC] = @RestrikcijaNC AND @RestrikcijaNC is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaStaticTable_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaStaticTable_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblArtiklSpecifikacijaStaticTable table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDArtiklSpecifikacija],
					[Vrijednost]
				FROM
					[dbo].[tblArtiklSpecifikacijaStaticTable]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaStaticTable_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaStaticTable_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblArtiklSpecifikacijaStaticTable table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDArtiklSpecifikacija]'
				SET @SQL = @SQL + ', [Vrijednost]'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklSpecifikacijaStaticTable]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDArtiklSpecifikacija],'
				SET @SQL = @SQL + ' [Vrijednost]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklSpecifikacijaStaticTable]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaStaticTable_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaStaticTable_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblArtiklSpecifikacijaStaticTable table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_Insert
(

	@ID int    OUTPUT,

	@IDArtiklSpecifikacija int   ,

	@Vrijednost nvarchar (500)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblArtiklSpecifikacijaStaticTable]
					(
					[IDArtiklSpecifikacija]
					,[Vrijednost]
					)
				VALUES
					(
					@IDArtiklSpecifikacija
					,@Vrijednost
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaStaticTable_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaStaticTable_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblArtiklSpecifikacijaStaticTable table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_Update
(

	@ID int   ,

	@IDArtiklSpecifikacija int   ,

	@Vrijednost nvarchar (500)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblArtiklSpecifikacijaStaticTable]
				SET
					[IDArtiklSpecifikacija] = @IDArtiklSpecifikacija
					,[Vrijednost] = @Vrijednost
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaStaticTable_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaStaticTable_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblArtiklSpecifikacijaStaticTable table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblArtiklSpecifikacijaStaticTable] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaStaticTable_GetByIDArtiklSpecifikacija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaStaticTable_GetByIDArtiklSpecifikacija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_GetByIDArtiklSpecifikacija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklSpecifikacijaStaticTable table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_GetByIDArtiklSpecifikacija
(

	@IDArtiklSpecifikacija int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDArtiklSpecifikacija],
					[Vrijednost]
				FROM
					[dbo].[tblArtiklSpecifikacijaStaticTable]
				WHERE
					[IDArtiklSpecifikacija] = @IDArtiklSpecifikacija
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaStaticTable_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaStaticTable_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklSpecifikacijaStaticTable table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDArtiklSpecifikacija],
					[Vrijednost]
				FROM
					[dbo].[tblArtiklSpecifikacijaStaticTable]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklSpecifikacijaStaticTable_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklSpecifikacijaStaticTable_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblArtiklSpecifikacijaStaticTable table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklSpecifikacijaStaticTable_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDArtiklSpecifikacija int   = null ,

	@Vrijednost nvarchar (500)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDArtiklSpecifikacija]
	, [Vrijednost]
    FROM
	[dbo].[tblArtiklSpecifikacijaStaticTable]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDArtiklSpecifikacija] = @IDArtiklSpecifikacija OR @IDArtiklSpecifikacija is null)
	AND ([Vrijednost] = @Vrijednost OR @Vrijednost is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDArtiklSpecifikacija]
	, [Vrijednost]
    FROM
	[dbo].[tblArtiklSpecifikacijaStaticTable]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDArtiklSpecifikacija] = @IDArtiklSpecifikacija AND @IDArtiklSpecifikacija is not null)
	OR ([Vrijednost] = @Vrijednost AND @Vrijednost is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblArtiklVrijednosti table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Tekstualno],
					[CijeliBroj],
					[RealanBroj],
					[Datum],
					[Slika],
					[IDArtiklSpecifikacija],
					[IDArtikl]
				FROM
					[dbo].[tblArtiklVrijednosti]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblArtiklVrijednosti table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Tekstualno]'
				SET @SQL = @SQL + ', [CijeliBroj]'
				SET @SQL = @SQL + ', [RealanBroj]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [Slika]'
				SET @SQL = @SQL + ', [IDArtiklSpecifikacija]'
				SET @SQL = @SQL + ', [IDArtikl]'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklVrijednosti]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Tekstualno],'
				SET @SQL = @SQL + ' [CijeliBroj],'
				SET @SQL = @SQL + ' [RealanBroj],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [Slika],'
				SET @SQL = @SQL + ' [IDArtiklSpecifikacija],'
				SET @SQL = @SQL + ' [IDArtikl]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblArtiklVrijednosti]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblArtiklVrijednosti table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_Insert
(

	@ID int    OUTPUT,

	@Tekstualno nvarchar (500)  ,

	@CijeliBroj int   ,

	@RealanBroj real   ,

	@Datum datetime   ,

	@Slika image   ,

	@IDArtiklSpecifikacija int   ,

	@IDArtikl int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblArtiklVrijednosti]
					(
					[Tekstualno]
					,[CijeliBroj]
					,[RealanBroj]
					,[Datum]
					,[Slika]
					,[IDArtiklSpecifikacija]
					,[IDArtikl]
					)
				VALUES
					(
					@Tekstualno
					,@CijeliBroj
					,@RealanBroj
					,@Datum
					,@Slika
					,@IDArtiklSpecifikacija
					,@IDArtikl
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblArtiklVrijednosti table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_Update
(

	@ID int   ,

	@Tekstualno nvarchar (500)  ,

	@CijeliBroj int   ,

	@RealanBroj real   ,

	@Datum datetime   ,

	@Slika image   ,

	@IDArtiklSpecifikacija int   ,

	@IDArtikl int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblArtiklVrijednosti]
				SET
					[Tekstualno] = @Tekstualno
					,[CijeliBroj] = @CijeliBroj
					,[RealanBroj] = @RealanBroj
					,[Datum] = @Datum
					,[Slika] = @Slika
					,[IDArtiklSpecifikacija] = @IDArtiklSpecifikacija
					,[IDArtikl] = @IDArtikl
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblArtiklVrijednosti table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblArtiklVrijednosti] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_GetByIDArtikl procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_GetByIDArtikl') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_GetByIDArtikl
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklVrijednosti table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_GetByIDArtikl
(

	@IDArtikl int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Tekstualno],
					[CijeliBroj],
					[RealanBroj],
					[Datum],
					[Slika],
					[IDArtiklSpecifikacija],
					[IDArtikl]
				FROM
					[dbo].[tblArtiklVrijednosti]
				WHERE
					[IDArtikl] = @IDArtikl
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_GetByIDArtiklSpecifikacija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_GetByIDArtiklSpecifikacija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_GetByIDArtiklSpecifikacija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklVrijednosti table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_GetByIDArtiklSpecifikacija
(

	@IDArtiklSpecifikacija int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Tekstualno],
					[CijeliBroj],
					[RealanBroj],
					[Datum],
					[Slika],
					[IDArtiklSpecifikacija],
					[IDArtikl]
				FROM
					[dbo].[tblArtiklVrijednosti]
				WHERE
					[IDArtiklSpecifikacija] = @IDArtiklSpecifikacija
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_GetByIDArtiklIDArtiklSpecifikacijaID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_GetByIDArtiklIDArtiklSpecifikacijaID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_GetByIDArtiklIDArtiklSpecifikacijaID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklVrijednosti table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_GetByIDArtiklIDArtiklSpecifikacijaID
(

	@IDArtikl int   ,

	@IDArtiklSpecifikacija int   ,

	@ID int   
)
AS


				SELECT
					[ID],
					[Tekstualno],
					[CijeliBroj],
					[RealanBroj],
					[Datum],
					[Slika],
					[IDArtiklSpecifikacija],
					[IDArtikl]
				FROM
					[dbo].[tblArtiklVrijednosti]
				WHERE
					[IDArtikl] = @IDArtikl
					AND [IDArtiklSpecifikacija] = @IDArtiklSpecifikacija
					AND [ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_GetByIDArtiklIDArtiklSpecifikacija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_GetByIDArtiklIDArtiklSpecifikacija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_GetByIDArtiklIDArtiklSpecifikacija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklVrijednosti table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_GetByIDArtiklIDArtiklSpecifikacija
(

	@IDArtikl int   ,

	@IDArtiklSpecifikacija int   
)
AS


				SELECT
					[ID],
					[Tekstualno],
					[CijeliBroj],
					[RealanBroj],
					[Datum],
					[Slika],
					[IDArtiklSpecifikacija],
					[IDArtikl]
				FROM
					[dbo].[tblArtiklVrijednosti]
				WHERE
					[IDArtikl] = @IDArtikl
					AND [IDArtiklSpecifikacija] = @IDArtiklSpecifikacija
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblArtiklVrijednosti table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Tekstualno],
					[CijeliBroj],
					[RealanBroj],
					[Datum],
					[Slika],
					[IDArtiklSpecifikacija],
					[IDArtikl]
				FROM
					[dbo].[tblArtiklVrijednosti]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblArtiklVrijednosti_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblArtiklVrijednosti_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblArtiklVrijednosti_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblArtiklVrijednosti table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblArtiklVrijednosti_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Tekstualno nvarchar (500)  = null ,

	@CijeliBroj int   = null ,

	@RealanBroj real   = null ,

	@Datum datetime   = null ,

	@Slika image   = null ,

	@IDArtiklSpecifikacija int   = null ,

	@IDArtikl int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Tekstualno]
	, [CijeliBroj]
	, [RealanBroj]
	, [Datum]
	, [Slika]
	, [IDArtiklSpecifikacija]
	, [IDArtikl]
    FROM
	[dbo].[tblArtiklVrijednosti]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Tekstualno] = @Tekstualno OR @Tekstualno is null)
	AND ([CijeliBroj] = @CijeliBroj OR @CijeliBroj is null)
	AND ([RealanBroj] = @RealanBroj OR @RealanBroj is null)
	AND ([Datum] = @Datum OR @Datum is null)
	AND ([IDArtiklSpecifikacija] = @IDArtiklSpecifikacija OR @IDArtiklSpecifikacija is null)
	AND ([IDArtikl] = @IDArtikl OR @IDArtikl is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Tekstualno]
	, [CijeliBroj]
	, [RealanBroj]
	, [Datum]
	, [Slika]
	, [IDArtiklSpecifikacija]
	, [IDArtikl]
    FROM
	[dbo].[tblArtiklVrijednosti]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Tekstualno] = @Tekstualno AND @Tekstualno is not null)
	OR ([CijeliBroj] = @CijeliBroj AND @CijeliBroj is not null)
	OR ([RealanBroj] = @RealanBroj AND @RealanBroj is not null)
	OR ([Datum] = @Datum AND @Datum is not null)
	OR ([IDArtiklSpecifikacija] = @IDArtiklSpecifikacija AND @IDArtiklSpecifikacija is not null)
	OR ([IDArtikl] = @IDArtikl AND @IDArtikl is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblNetoBruto_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblNetoBruto_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblNetoBruto_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblNetoBruto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblNetoBruto_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[StopaPrireza],
					[Kpr],
					[Kpr25],
					[Kpr35],
					[Kpr45]
				FROM
					[pla].[tblNetoBruto]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblNetoBruto_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblNetoBruto_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblNetoBruto_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblNetoBruto table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblNetoBruto_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [StopaPrireza]'
				SET @SQL = @SQL + ', [Kpr]'
				SET @SQL = @SQL + ', [Kpr25]'
				SET @SQL = @SQL + ', [Kpr35]'
				SET @SQL = @SQL + ', [Kpr45]'
				SET @SQL = @SQL + ' FROM [pla].[tblNetoBruto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [StopaPrireza],'
				SET @SQL = @SQL + ' [Kpr],'
				SET @SQL = @SQL + ' [Kpr25],'
				SET @SQL = @SQL + ' [Kpr35],'
				SET @SQL = @SQL + ' [Kpr45]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblNetoBruto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblNetoBruto_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblNetoBruto_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblNetoBruto_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblNetoBruto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblNetoBruto_Insert
(

	@ID int    OUTPUT,

	@StopaPrireza money   ,

	@Kpr real   ,

	@Kpr25 real   ,

	@Kpr35 real   ,

	@Kpr45 real   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblNetoBruto]
					(
					[StopaPrireza]
					,[Kpr]
					,[Kpr25]
					,[Kpr35]
					,[Kpr45]
					)
				VALUES
					(
					@StopaPrireza
					,@Kpr
					,@Kpr25
					,@Kpr35
					,@Kpr45
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblNetoBruto_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblNetoBruto_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblNetoBruto_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblNetoBruto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblNetoBruto_Update
(

	@ID int   ,

	@StopaPrireza money   ,

	@Kpr real   ,

	@Kpr25 real   ,

	@Kpr35 real   ,

	@Kpr45 real   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblNetoBruto]
				SET
					[StopaPrireza] = @StopaPrireza
					,[Kpr] = @Kpr
					,[Kpr25] = @Kpr25
					,[Kpr35] = @Kpr35
					,[Kpr45] = @Kpr45
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblNetoBruto_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblNetoBruto_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblNetoBruto_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblNetoBruto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblNetoBruto_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblNetoBruto] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblNetoBruto_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblNetoBruto_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblNetoBruto_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblNetoBruto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblNetoBruto_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[StopaPrireza],
					[Kpr],
					[Kpr25],
					[Kpr35],
					[Kpr45]
				FROM
					[pla].[tblNetoBruto]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblNetoBruto_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblNetoBruto_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblNetoBruto_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblNetoBruto table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblNetoBruto_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@StopaPrireza money   = null ,

	@Kpr real   = null ,

	@Kpr25 real   = null ,

	@Kpr35 real   = null ,

	@Kpr45 real   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [StopaPrireza]
	, [Kpr]
	, [Kpr25]
	, [Kpr35]
	, [Kpr45]
    FROM
	[pla].[tblNetoBruto]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([StopaPrireza] = @StopaPrireza OR @StopaPrireza is null)
	AND ([Kpr] = @Kpr OR @Kpr is null)
	AND ([Kpr25] = @Kpr25 OR @Kpr25 is null)
	AND ([Kpr35] = @Kpr35 OR @Kpr35 is null)
	AND ([Kpr45] = @Kpr45 OR @Kpr45 is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [StopaPrireza]
	, [Kpr]
	, [Kpr25]
	, [Kpr35]
	, [Kpr45]
    FROM
	[pla].[tblNetoBruto]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([StopaPrireza] = @StopaPrireza AND @StopaPrireza is not null)
	OR ([Kpr] = @Kpr AND @Kpr is not null)
	OR ([Kpr25] = @Kpr25 AND @Kpr25 is not null)
	OR ([Kpr35] = @Kpr35 AND @Kpr35 is not null)
	OR ([Kpr45] = @Kpr45 AND @Kpr45 is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjestoTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjestoTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjestoTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblMjestoTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjestoTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblMjestoTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjestoTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjestoTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjestoTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblMjestoTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjestoTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [dbo].[tblMjestoTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblMjestoTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjestoTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjestoTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjestoTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblMjestoTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjestoTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblMjestoTip]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjestoTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjestoTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjestoTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblMjestoTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjestoTip_Update
(

	@ID int   ,

	@Naziv nvarchar (100)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblMjestoTip]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjestoTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjestoTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjestoTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblMjestoTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjestoTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblMjestoTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjestoTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjestoTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjestoTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblMjestoTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjestoTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblMjestoTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjestoTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjestoTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjestoTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblMjestoTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjestoTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (100)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblMjestoTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblMjestoTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNAppUpdate_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNAppUpdate_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNAppUpdate_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblNAppUpdate table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNAppUpdate_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[Version],
					[Date],
					[Snapshot],
					[Location]
				FROM
					[dbo].[tblNAppUpdate]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNAppUpdate_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNAppUpdate_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNAppUpdate_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblNAppUpdate table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNAppUpdate_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Version]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Version]'
				SET @SQL = @SQL + ', [Date]'
				SET @SQL = @SQL + ', [Snapshot]'
				SET @SQL = @SQL + ', [Location]'
				SET @SQL = @SQL + ' FROM [dbo].[tblNAppUpdate]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Version],'
				SET @SQL = @SQL + ' [Date],'
				SET @SQL = @SQL + ' [Snapshot],'
				SET @SQL = @SQL + ' [Location]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblNAppUpdate]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNAppUpdate_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNAppUpdate_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNAppUpdate_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblNAppUpdate table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNAppUpdate_Insert
(

	@Version nvarchar (50)  ,

	@Date datetime   ,

	@Snapshot bit   ,

	@Location nvarchar (300)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblNAppUpdate]
					(
					[Version]
					,[Date]
					,[Snapshot]
					,[Location]
					)
				VALUES
					(
					@Version
					,@Date
					,@Snapshot
					,@Location
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNAppUpdate_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNAppUpdate_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNAppUpdate_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblNAppUpdate table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNAppUpdate_Update
(

	@Version nvarchar (50)  ,

	@OriginalVersion nvarchar (50)  ,

	@Date datetime   ,

	@Snapshot bit   ,

	@Location nvarchar (300)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblNAppUpdate]
				SET
					[Version] = @Version
					,[Date] = @Date
					,[Snapshot] = @Snapshot
					,[Location] = @Location
				WHERE
[Version] = @OriginalVersion 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNAppUpdate_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNAppUpdate_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNAppUpdate_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblNAppUpdate table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNAppUpdate_Delete
(

	@Version nvarchar (50)  
)
AS


				DELETE FROM [dbo].[tblNAppUpdate] WITH (ROWLOCK) 
				WHERE
					[Version] = @Version
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNAppUpdate_GetByVersion procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNAppUpdate_GetByVersion') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNAppUpdate_GetByVersion
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblNAppUpdate table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNAppUpdate_GetByVersion
(

	@Version nvarchar (50)  
)
AS


				SELECT
					[Version],
					[Date],
					[Snapshot],
					[Location]
				FROM
					[dbo].[tblNAppUpdate]
				WHERE
					[Version] = @Version
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNAppUpdate_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNAppUpdate_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNAppUpdate_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblNAppUpdate table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNAppUpdate_Find
(

	@SearchUsingOR bit   = null ,

	@Version nvarchar (50)  = null ,

	@Date datetime   = null ,

	@Snapshot bit   = null ,

	@Location nvarchar (300)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Version]
	, [Date]
	, [Snapshot]
	, [Location]
    FROM
	[dbo].[tblNAppUpdate]
    WHERE 
	 ([Version] = @Version OR @Version is null)
	AND ([Date] = @Date OR @Date is null)
	AND ([Snapshot] = @Snapshot OR @Snapshot is null)
	AND ([Location] = @Location OR @Location is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Version]
	, [Date]
	, [Snapshot]
	, [Location]
    FROM
	[dbo].[tblNAppUpdate]
    WHERE 
	 ([Version] = @Version AND @Version is not null)
	OR ([Date] = @Date AND @Date is not null)
	OR ([Snapshot] = @Snapshot AND @Snapshot is not null)
	OR ([Location] = @Location AND @Location is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracun_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracun_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracun_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracun_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[VrstaUplateRSM],
					[RedniBrojUGodini],
					[MinimalniOsobniOdbitak],
					[FondSati],
					[MaksimalniIznosPorezneOlaksice],
					[IdentifikatorIDObrasca],
					[BrutoOsnovica],
					[DoprinosPoDanuBoravkaUInozemstvu],
					[Status],
					[DoprinosZdravstveno],
					[DoprinosZaposljavanje],
					[DoprinosNezgoda],
					[RSMVrstaObveznika],
					[DatumIsplate],
					[MIO1aPostotak],
					[MIO1bPostotak],
					[MIO2Postotak],
					[NajvisaMjOsnovica],
					[DoprinosZaposljavanjeSInvaliditetom],
					[IznosZdravstvenogZaInozemstvo]
				FROM
					[pla].[tblObracun]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracun_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracun_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracun_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracun table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracun_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [VrstaUplateRSM]'
				SET @SQL = @SQL + ', [RedniBrojUGodini]'
				SET @SQL = @SQL + ', [MinimalniOsobniOdbitak]'
				SET @SQL = @SQL + ', [FondSati]'
				SET @SQL = @SQL + ', [MaksimalniIznosPorezneOlaksice]'
				SET @SQL = @SQL + ', [IdentifikatorIDObrasca]'
				SET @SQL = @SQL + ', [BrutoOsnovica]'
				SET @SQL = @SQL + ', [DoprinosPoDanuBoravkaUInozemstvu]'
				SET @SQL = @SQL + ', [Status]'
				SET @SQL = @SQL + ', [DoprinosZdravstveno]'
				SET @SQL = @SQL + ', [DoprinosZaposljavanje]'
				SET @SQL = @SQL + ', [DoprinosNezgoda]'
				SET @SQL = @SQL + ', [RSMVrstaObveznika]'
				SET @SQL = @SQL + ', [DatumIsplate]'
				SET @SQL = @SQL + ', [MIO1aPostotak]'
				SET @SQL = @SQL + ', [MIO1bPostotak]'
				SET @SQL = @SQL + ', [MIO2Postotak]'
				SET @SQL = @SQL + ', [NajvisaMjOsnovica]'
				SET @SQL = @SQL + ', [DoprinosZaposljavanjeSInvaliditetom]'
				SET @SQL = @SQL + ', [IznosZdravstvenogZaInozemstvo]'
				SET @SQL = @SQL + ' FROM [pla].[tblObracun]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [VrstaUplateRSM],'
				SET @SQL = @SQL + ' [RedniBrojUGodini],'
				SET @SQL = @SQL + ' [MinimalniOsobniOdbitak],'
				SET @SQL = @SQL + ' [FondSati],'
				SET @SQL = @SQL + ' [MaksimalniIznosPorezneOlaksice],'
				SET @SQL = @SQL + ' [IdentifikatorIDObrasca],'
				SET @SQL = @SQL + ' [BrutoOsnovica],'
				SET @SQL = @SQL + ' [DoprinosPoDanuBoravkaUInozemstvu],'
				SET @SQL = @SQL + ' [Status],'
				SET @SQL = @SQL + ' [DoprinosZdravstveno],'
				SET @SQL = @SQL + ' [DoprinosZaposljavanje],'
				SET @SQL = @SQL + ' [DoprinosNezgoda],'
				SET @SQL = @SQL + ' [RSMVrstaObveznika],'
				SET @SQL = @SQL + ' [DatumIsplate],'
				SET @SQL = @SQL + ' [MIO1aPostotak],'
				SET @SQL = @SQL + ' [MIO1bPostotak],'
				SET @SQL = @SQL + ' [MIO2Postotak],'
				SET @SQL = @SQL + ' [NajvisaMjOsnovica],'
				SET @SQL = @SQL + ' [DoprinosZaposljavanjeSInvaliditetom],'
				SET @SQL = @SQL + ' [IznosZdravstvenogZaInozemstvo]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblObracun]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracun_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracun_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracun_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracun_Insert
(

	@ID int    OUTPUT,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@VrstaUplateRSM int   ,

	@RedniBrojUGodini int   ,

	@MinimalniOsobniOdbitak money   ,

	@FondSati real   ,

	@MaksimalniIznosPorezneOlaksice money   ,

	@IdentifikatorIDObrasca int   ,

	@BrutoOsnovica money   ,

	@DoprinosPoDanuBoravkaUInozemstvu money   ,

	@Status int   ,

	@DoprinosZdravstveno money   ,

	@DoprinosZaposljavanje money   ,

	@DoprinosNezgoda money   ,

	@RSMVrstaObveznika int   ,

	@DatumIsplate datetime   ,

	@MIO1aPostotak real   ,

	@MIO1bPostotak real   ,

	@MIO2Postotak real   ,

	@NajvisaMjOsnovica money   ,

	@DoprinosZaposljavanjeSInvaliditetom money   ,

	@IznosZdravstvenogZaInozemstvo money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblObracun]
					(
					[DatumOd]
					,[DatumDo]
					,[VrstaUplateRSM]
					,[RedniBrojUGodini]
					,[MinimalniOsobniOdbitak]
					,[FondSati]
					,[MaksimalniIznosPorezneOlaksice]
					,[IdentifikatorIDObrasca]
					,[BrutoOsnovica]
					,[DoprinosPoDanuBoravkaUInozemstvu]
					,[Status]
					,[DoprinosZdravstveno]
					,[DoprinosZaposljavanje]
					,[DoprinosNezgoda]
					,[RSMVrstaObveznika]
					,[DatumIsplate]
					,[MIO1aPostotak]
					,[MIO1bPostotak]
					,[MIO2Postotak]
					,[NajvisaMjOsnovica]
					,[DoprinosZaposljavanjeSInvaliditetom]
					,[IznosZdravstvenogZaInozemstvo]
					)
				VALUES
					(
					@DatumOd
					,@DatumDo
					,@VrstaUplateRSM
					,@RedniBrojUGodini
					,@MinimalniOsobniOdbitak
					,@FondSati
					,@MaksimalniIznosPorezneOlaksice
					,@IdentifikatorIDObrasca
					,@BrutoOsnovica
					,@DoprinosPoDanuBoravkaUInozemstvu
					,@Status
					,@DoprinosZdravstveno
					,@DoprinosZaposljavanje
					,@DoprinosNezgoda
					,@RSMVrstaObveznika
					,@DatumIsplate
					,@MIO1aPostotak
					,@MIO1bPostotak
					,@MIO2Postotak
					,@NajvisaMjOsnovica
					,@DoprinosZaposljavanjeSInvaliditetom
					,@IznosZdravstvenogZaInozemstvo
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracun_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracun_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracun_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracun_Update
(

	@ID int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@VrstaUplateRSM int   ,

	@RedniBrojUGodini int   ,

	@MinimalniOsobniOdbitak money   ,

	@FondSati real   ,

	@MaksimalniIznosPorezneOlaksice money   ,

	@IdentifikatorIDObrasca int   ,

	@BrutoOsnovica money   ,

	@DoprinosPoDanuBoravkaUInozemstvu money   ,

	@Status int   ,

	@DoprinosZdravstveno money   ,

	@DoprinosZaposljavanje money   ,

	@DoprinosNezgoda money   ,

	@RSMVrstaObveznika int   ,

	@DatumIsplate datetime   ,

	@MIO1aPostotak real   ,

	@MIO1bPostotak real   ,

	@MIO2Postotak real   ,

	@NajvisaMjOsnovica money   ,

	@DoprinosZaposljavanjeSInvaliditetom money   ,

	@IznosZdravstvenogZaInozemstvo money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblObracun]
				SET
					[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[VrstaUplateRSM] = @VrstaUplateRSM
					,[RedniBrojUGodini] = @RedniBrojUGodini
					,[MinimalniOsobniOdbitak] = @MinimalniOsobniOdbitak
					,[FondSati] = @FondSati
					,[MaksimalniIznosPorezneOlaksice] = @MaksimalniIznosPorezneOlaksice
					,[IdentifikatorIDObrasca] = @IdentifikatorIDObrasca
					,[BrutoOsnovica] = @BrutoOsnovica
					,[DoprinosPoDanuBoravkaUInozemstvu] = @DoprinosPoDanuBoravkaUInozemstvu
					,[Status] = @Status
					,[DoprinosZdravstveno] = @DoprinosZdravstveno
					,[DoprinosZaposljavanje] = @DoprinosZaposljavanje
					,[DoprinosNezgoda] = @DoprinosNezgoda
					,[RSMVrstaObveznika] = @RSMVrstaObveznika
					,[DatumIsplate] = @DatumIsplate
					,[MIO1aPostotak] = @MIO1aPostotak
					,[MIO1bPostotak] = @MIO1bPostotak
					,[MIO2Postotak] = @MIO2Postotak
					,[NajvisaMjOsnovica] = @NajvisaMjOsnovica
					,[DoprinosZaposljavanjeSInvaliditetom] = @DoprinosZaposljavanjeSInvaliditetom
					,[IznosZdravstvenogZaInozemstvo] = @IznosZdravstvenogZaInozemstvo
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracun_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracun_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracun_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracun_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblObracun] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracun_GetByIdentifikatorIDObrasca procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracun_GetByIdentifikatorIDObrasca') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracun_GetByIdentifikatorIDObrasca
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracun table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracun_GetByIdentifikatorIDObrasca
(

	@IdentifikatorIDObrasca int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[VrstaUplateRSM],
					[RedniBrojUGodini],
					[MinimalniOsobniOdbitak],
					[FondSati],
					[MaksimalniIznosPorezneOlaksice],
					[IdentifikatorIDObrasca],
					[BrutoOsnovica],
					[DoprinosPoDanuBoravkaUInozemstvu],
					[Status],
					[DoprinosZdravstveno],
					[DoprinosZaposljavanje],
					[DoprinosNezgoda],
					[RSMVrstaObveznika],
					[DatumIsplate],
					[MIO1aPostotak],
					[MIO1bPostotak],
					[MIO2Postotak],
					[NajvisaMjOsnovica],
					[DoprinosZaposljavanjeSInvaliditetom],
					[IznosZdravstvenogZaInozemstvo]
				FROM
					[pla].[tblObracun]
				WHERE
					[IdentifikatorIDObrasca] = @IdentifikatorIDObrasca
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracun_GetByVrstaUplateRSM procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracun_GetByVrstaUplateRSM') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracun_GetByVrstaUplateRSM
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracun table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracun_GetByVrstaUplateRSM
(

	@VrstaUplateRSM int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[VrstaUplateRSM],
					[RedniBrojUGodini],
					[MinimalniOsobniOdbitak],
					[FondSati],
					[MaksimalniIznosPorezneOlaksice],
					[IdentifikatorIDObrasca],
					[BrutoOsnovica],
					[DoprinosPoDanuBoravkaUInozemstvu],
					[Status],
					[DoprinosZdravstveno],
					[DoprinosZaposljavanje],
					[DoprinosNezgoda],
					[RSMVrstaObveznika],
					[DatumIsplate],
					[MIO1aPostotak],
					[MIO1bPostotak],
					[MIO2Postotak],
					[NajvisaMjOsnovica],
					[DoprinosZaposljavanjeSInvaliditetom],
					[IznosZdravstvenogZaInozemstvo]
				FROM
					[pla].[tblObracun]
				WHERE
					[VrstaUplateRSM] = @VrstaUplateRSM
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracun_GetByRSMVrstaObveznika procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracun_GetByRSMVrstaObveznika') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracun_GetByRSMVrstaObveznika
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracun table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracun_GetByRSMVrstaObveznika
(

	@RSMVrstaObveznika int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[VrstaUplateRSM],
					[RedniBrojUGodini],
					[MinimalniOsobniOdbitak],
					[FondSati],
					[MaksimalniIznosPorezneOlaksice],
					[IdentifikatorIDObrasca],
					[BrutoOsnovica],
					[DoprinosPoDanuBoravkaUInozemstvu],
					[Status],
					[DoprinosZdravstveno],
					[DoprinosZaposljavanje],
					[DoprinosNezgoda],
					[RSMVrstaObveznika],
					[DatumIsplate],
					[MIO1aPostotak],
					[MIO1bPostotak],
					[MIO2Postotak],
					[NajvisaMjOsnovica],
					[DoprinosZaposljavanjeSInvaliditetom],
					[IznosZdravstvenogZaInozemstvo]
				FROM
					[pla].[tblObracun]
				WHERE
					[RSMVrstaObveznika] = @RSMVrstaObveznika
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracun_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracun_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracun_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracun table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracun_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[VrstaUplateRSM],
					[RedniBrojUGodini],
					[MinimalniOsobniOdbitak],
					[FondSati],
					[MaksimalniIznosPorezneOlaksice],
					[IdentifikatorIDObrasca],
					[BrutoOsnovica],
					[DoprinosPoDanuBoravkaUInozemstvu],
					[Status],
					[DoprinosZdravstveno],
					[DoprinosZaposljavanje],
					[DoprinosNezgoda],
					[RSMVrstaObveznika],
					[DatumIsplate],
					[MIO1aPostotak],
					[MIO1bPostotak],
					[MIO2Postotak],
					[NajvisaMjOsnovica],
					[DoprinosZaposljavanjeSInvaliditetom],
					[IznosZdravstvenogZaInozemstvo]
				FROM
					[pla].[tblObracun]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracun_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracun_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracun_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracun table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracun_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@VrstaUplateRSM int   = null ,

	@RedniBrojUGodini int   = null ,

	@MinimalniOsobniOdbitak money   = null ,

	@FondSati real   = null ,

	@MaksimalniIznosPorezneOlaksice money   = null ,

	@IdentifikatorIDObrasca int   = null ,

	@BrutoOsnovica money   = null ,

	@DoprinosPoDanuBoravkaUInozemstvu money   = null ,

	@Status int   = null ,

	@DoprinosZdravstveno money   = null ,

	@DoprinosZaposljavanje money   = null ,

	@DoprinosNezgoda money   = null ,

	@RSMVrstaObveznika int   = null ,

	@DatumIsplate datetime   = null ,

	@MIO1aPostotak real   = null ,

	@MIO1bPostotak real   = null ,

	@MIO2Postotak real   = null ,

	@NajvisaMjOsnovica money   = null ,

	@DoprinosZaposljavanjeSInvaliditetom money   = null ,

	@IznosZdravstvenogZaInozemstvo money   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [DatumOd]
	, [DatumDo]
	, [VrstaUplateRSM]
	, [RedniBrojUGodini]
	, [MinimalniOsobniOdbitak]
	, [FondSati]
	, [MaksimalniIznosPorezneOlaksice]
	, [IdentifikatorIDObrasca]
	, [BrutoOsnovica]
	, [DoprinosPoDanuBoravkaUInozemstvu]
	, [Status]
	, [DoprinosZdravstveno]
	, [DoprinosZaposljavanje]
	, [DoprinosNezgoda]
	, [RSMVrstaObveznika]
	, [DatumIsplate]
	, [MIO1aPostotak]
	, [MIO1bPostotak]
	, [MIO2Postotak]
	, [NajvisaMjOsnovica]
	, [DoprinosZaposljavanjeSInvaliditetom]
	, [IznosZdravstvenogZaInozemstvo]
    FROM
	[pla].[tblObracun]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([VrstaUplateRSM] = @VrstaUplateRSM OR @VrstaUplateRSM is null)
	AND ([RedniBrojUGodini] = @RedniBrojUGodini OR @RedniBrojUGodini is null)
	AND ([MinimalniOsobniOdbitak] = @MinimalniOsobniOdbitak OR @MinimalniOsobniOdbitak is null)
	AND ([FondSati] = @FondSati OR @FondSati is null)
	AND ([MaksimalniIznosPorezneOlaksice] = @MaksimalniIznosPorezneOlaksice OR @MaksimalniIznosPorezneOlaksice is null)
	AND ([IdentifikatorIDObrasca] = @IdentifikatorIDObrasca OR @IdentifikatorIDObrasca is null)
	AND ([BrutoOsnovica] = @BrutoOsnovica OR @BrutoOsnovica is null)
	AND ([DoprinosPoDanuBoravkaUInozemstvu] = @DoprinosPoDanuBoravkaUInozemstvu OR @DoprinosPoDanuBoravkaUInozemstvu is null)
	AND ([Status] = @Status OR @Status is null)
	AND ([DoprinosZdravstveno] = @DoprinosZdravstveno OR @DoprinosZdravstveno is null)
	AND ([DoprinosZaposljavanje] = @DoprinosZaposljavanje OR @DoprinosZaposljavanje is null)
	AND ([DoprinosNezgoda] = @DoprinosNezgoda OR @DoprinosNezgoda is null)
	AND ([RSMVrstaObveznika] = @RSMVrstaObveznika OR @RSMVrstaObveznika is null)
	AND ([DatumIsplate] = @DatumIsplate OR @DatumIsplate is null)
	AND ([MIO1aPostotak] = @MIO1aPostotak OR @MIO1aPostotak is null)
	AND ([MIO1bPostotak] = @MIO1bPostotak OR @MIO1bPostotak is null)
	AND ([MIO2Postotak] = @MIO2Postotak OR @MIO2Postotak is null)
	AND ([NajvisaMjOsnovica] = @NajvisaMjOsnovica OR @NajvisaMjOsnovica is null)
	AND ([DoprinosZaposljavanjeSInvaliditetom] = @DoprinosZaposljavanjeSInvaliditetom OR @DoprinosZaposljavanjeSInvaliditetom is null)
	AND ([IznosZdravstvenogZaInozemstvo] = @IznosZdravstvenogZaInozemstvo OR @IznosZdravstvenogZaInozemstvo is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [DatumOd]
	, [DatumDo]
	, [VrstaUplateRSM]
	, [RedniBrojUGodini]
	, [MinimalniOsobniOdbitak]
	, [FondSati]
	, [MaksimalniIznosPorezneOlaksice]
	, [IdentifikatorIDObrasca]
	, [BrutoOsnovica]
	, [DoprinosPoDanuBoravkaUInozemstvu]
	, [Status]
	, [DoprinosZdravstveno]
	, [DoprinosZaposljavanje]
	, [DoprinosNezgoda]
	, [RSMVrstaObveznika]
	, [DatumIsplate]
	, [MIO1aPostotak]
	, [MIO1bPostotak]
	, [MIO2Postotak]
	, [NajvisaMjOsnovica]
	, [DoprinosZaposljavanjeSInvaliditetom]
	, [IznosZdravstvenogZaInozemstvo]
    FROM
	[pla].[tblObracun]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([VrstaUplateRSM] = @VrstaUplateRSM AND @VrstaUplateRSM is not null)
	OR ([RedniBrojUGodini] = @RedniBrojUGodini AND @RedniBrojUGodini is not null)
	OR ([MinimalniOsobniOdbitak] = @MinimalniOsobniOdbitak AND @MinimalniOsobniOdbitak is not null)
	OR ([FondSati] = @FondSati AND @FondSati is not null)
	OR ([MaksimalniIznosPorezneOlaksice] = @MaksimalniIznosPorezneOlaksice AND @MaksimalniIznosPorezneOlaksice is not null)
	OR ([IdentifikatorIDObrasca] = @IdentifikatorIDObrasca AND @IdentifikatorIDObrasca is not null)
	OR ([BrutoOsnovica] = @BrutoOsnovica AND @BrutoOsnovica is not null)
	OR ([DoprinosPoDanuBoravkaUInozemstvu] = @DoprinosPoDanuBoravkaUInozemstvu AND @DoprinosPoDanuBoravkaUInozemstvu is not null)
	OR ([Status] = @Status AND @Status is not null)
	OR ([DoprinosZdravstveno] = @DoprinosZdravstveno AND @DoprinosZdravstveno is not null)
	OR ([DoprinosZaposljavanje] = @DoprinosZaposljavanje AND @DoprinosZaposljavanje is not null)
	OR ([DoprinosNezgoda] = @DoprinosNezgoda AND @DoprinosNezgoda is not null)
	OR ([RSMVrstaObveznika] = @RSMVrstaObveznika AND @RSMVrstaObveznika is not null)
	OR ([DatumIsplate] = @DatumIsplate AND @DatumIsplate is not null)
	OR ([MIO1aPostotak] = @MIO1aPostotak AND @MIO1aPostotak is not null)
	OR ([MIO1bPostotak] = @MIO1bPostotak AND @MIO1bPostotak is not null)
	OR ([MIO2Postotak] = @MIO2Postotak AND @MIO2Postotak is not null)
	OR ([NajvisaMjOsnovica] = @NajvisaMjOsnovica AND @NajvisaMjOsnovica is not null)
	OR ([DoprinosZaposljavanjeSInvaliditetom] = @DoprinosZaposljavanjeSInvaliditetom AND @DoprinosZaposljavanjeSInvaliditetom is not null)
	OR ([IznosZdravstvenogZaInozemstvo] = @IznosZdravstvenogZaInozemstvo AND @IznosZdravstvenogZaInozemstvo is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinTransporta_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinTransporta_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinTransporta_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblNacinTransporta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinTransporta_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblNacinTransporta]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinTransporta_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinTransporta_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinTransporta_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblNacinTransporta table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinTransporta_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [dbo].[tblNacinTransporta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblNacinTransporta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinTransporta_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinTransporta_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinTransporta_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblNacinTransporta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinTransporta_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblNacinTransporta]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinTransporta_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinTransporta_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinTransporta_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblNacinTransporta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinTransporta_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblNacinTransporta]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinTransporta_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinTransporta_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinTransporta_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblNacinTransporta table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinTransporta_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblNacinTransporta] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinTransporta_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinTransporta_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinTransporta_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblNacinTransporta table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinTransporta_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblNacinTransporta]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinTransporta_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinTransporta_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinTransporta_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblNacinTransporta table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinTransporta_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblNacinTransporta]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblNacinTransporta]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikParametra_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikParametra_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikParametra_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblGrupaDjelatnikParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikParametra_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDGrupaDjelatnik],
					[IDGrupaParemetra]
				FROM
					[dbo].[tblGrupaDjelatnikParametra]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikParametra_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikParametra_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikParametra_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblGrupaDjelatnikParametra table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikParametra_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDGrupaDjelatnik]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDGrupaDjelatnik]'
				SET @SQL = @SQL + ', [IDGrupaParemetra]'
				SET @SQL = @SQL + ' FROM [dbo].[tblGrupaDjelatnikParametra]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDGrupaDjelatnik],'
				SET @SQL = @SQL + ' [IDGrupaParemetra]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblGrupaDjelatnikParametra]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikParametra_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikParametra_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikParametra_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblGrupaDjelatnikParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikParametra_Insert
(

	@IDGrupaDjelatnik int   ,

	@IDGrupaParemetra int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblGrupaDjelatnikParametra]
					(
					[IDGrupaDjelatnik]
					,[IDGrupaParemetra]
					)
				VALUES
					(
					@IDGrupaDjelatnik
					,@IDGrupaParemetra
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikParametra_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikParametra_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikParametra_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblGrupaDjelatnikParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikParametra_Update
(

	@IDGrupaDjelatnik int   ,

	@OriginalIDGrupaDjelatnik int   ,

	@IDGrupaParemetra int   ,

	@OriginalIDGrupaParemetra int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblGrupaDjelatnikParametra]
				SET
					[IDGrupaDjelatnik] = @IDGrupaDjelatnik
					,[IDGrupaParemetra] = @IDGrupaParemetra
				WHERE
[IDGrupaDjelatnik] = @OriginalIDGrupaDjelatnik 
AND [IDGrupaParemetra] = @OriginalIDGrupaParemetra 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikParametra_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikParametra_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikParametra_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblGrupaDjelatnikParametra table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikParametra_Delete
(

	@IDGrupaDjelatnik int   ,

	@IDGrupaParemetra int   
)
AS


				DELETE FROM [dbo].[tblGrupaDjelatnikParametra] WITH (ROWLOCK) 
				WHERE
					[IDGrupaDjelatnik] = @IDGrupaDjelatnik
					AND [IDGrupaParemetra] = @IDGrupaParemetra
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikParametra_GetByIDGrupaDjelatnik procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikParametra_GetByIDGrupaDjelatnik') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikParametra_GetByIDGrupaDjelatnik
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDjelatnikParametra table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikParametra_GetByIDGrupaDjelatnik
(

	@IDGrupaDjelatnik int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDGrupaDjelatnik],
					[IDGrupaParemetra]
				FROM
					[dbo].[tblGrupaDjelatnikParametra]
				WHERE
					[IDGrupaDjelatnik] = @IDGrupaDjelatnik
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikParametra_GetByIDGrupaParemetra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikParametra_GetByIDGrupaParemetra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikParametra_GetByIDGrupaParemetra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDjelatnikParametra table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikParametra_GetByIDGrupaParemetra
(

	@IDGrupaParemetra int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDGrupaDjelatnik],
					[IDGrupaParemetra]
				FROM
					[dbo].[tblGrupaDjelatnikParametra]
				WHERE
					[IDGrupaParemetra] = @IDGrupaParemetra
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikParametra_GetByIDGrupaDjelatnikIDGrupaParemetra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikParametra_GetByIDGrupaDjelatnikIDGrupaParemetra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikParametra_GetByIDGrupaDjelatnikIDGrupaParemetra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDjelatnikParametra table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikParametra_GetByIDGrupaDjelatnikIDGrupaParemetra
(

	@IDGrupaDjelatnik int   ,

	@IDGrupaParemetra int   
)
AS


				SELECT
					[IDGrupaDjelatnik],
					[IDGrupaParemetra]
				FROM
					[dbo].[tblGrupaDjelatnikParametra]
				WHERE
					[IDGrupaDjelatnik] = @IDGrupaDjelatnik
					AND [IDGrupaParemetra] = @IDGrupaParemetra
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikParametra_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikParametra_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikParametra_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblGrupaDjelatnikParametra table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikParametra_Find
(

	@SearchUsingOR bit   = null ,

	@IDGrupaDjelatnik int   = null ,

	@IDGrupaParemetra int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [IDGrupaDjelatnik]
	, [IDGrupaParemetra]
    FROM
	[dbo].[tblGrupaDjelatnikParametra]
    WHERE 
	 ([IDGrupaDjelatnik] = @IDGrupaDjelatnik OR @IDGrupaDjelatnik is null)
	AND ([IDGrupaParemetra] = @IDGrupaParemetra OR @IDGrupaParemetra is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [IDGrupaDjelatnik]
	, [IDGrupaParemetra]
    FROM
	[dbo].[tblGrupaDjelatnikParametra]
    WHERE 
	 ([IDGrupaDjelatnik] = @IDGrupaDjelatnik AND @IDGrupaDjelatnik is not null)
	OR ([IDGrupaParemetra] = @IDGrupaParemetra AND @IDGrupaParemetra is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblKonto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[PrijenosAnaliticki]
				FROM
					[fin].[tblKonto]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblKonto table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Sifra]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Analiticki]'
				SET @SQL = @SQL + ', [IDTip]'
				SET @SQL = @SQL + ', [IDKontoPoreza]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [PrijenosAnaliticki]'
				SET @SQL = @SQL + ' FROM [fin].[tblKonto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Sifra],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Analiticki],'
				SET @SQL = @SQL + ' [IDTip],'
				SET @SQL = @SQL + ' [IDKontoPoreza],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [PrijenosAnaliticki]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblKonto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblKonto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_Insert
(

	@ID int    OUTPUT,

	@Sifra varchar (9)  ,

	@Naziv nvarchar (250)  ,

	@Analiticki bit   ,

	@IDTip int   ,

	@IDKontoPoreza int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@PrijenosAnaliticki bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblKonto]
					(
					[Sifra]
					,[Naziv]
					,[Analiticki]
					,[IDTip]
					,[IDKontoPoreza]
					,[DatumOd]
					,[DatumDo]
					,[PrijenosAnaliticki]
					)
				VALUES
					(
					@Sifra
					,@Naziv
					,@Analiticki
					,@IDTip
					,@IDKontoPoreza
					,@DatumOd
					,@DatumDo
					,@PrijenosAnaliticki
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblKonto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_Update
(

	@ID int   ,

	@Sifra varchar (9)  ,

	@Naziv nvarchar (250)  ,

	@Analiticki bit   ,

	@IDTip int   ,

	@IDKontoPoreza int   ,

	@DatumOd datetime   ,

	@DatumDo datetime   ,

	@PrijenosAnaliticki bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblKonto]
				SET
					[Sifra] = @Sifra
					,[Naziv] = @Naziv
					,[Analiticki] = @Analiticki
					,[IDTip] = @IDTip
					,[IDKontoPoreza] = @IDKontoPoreza
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
					,[PrijenosAnaliticki] = @PrijenosAnaliticki
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblKonto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblKonto] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_GetByIDTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_GetByIDTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_GetByIDTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKonto table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_GetByIDTip
(

	@IDTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[PrijenosAnaliticki]
				FROM
					[fin].[tblKonto]
				WHERE
					[IDTip] = @IDTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_GetByIDSifra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_GetByIDSifra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_GetByIDSifra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKonto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_GetByIDSifra
(

	@ID int   ,

	@Sifra varchar (9)  
)
AS


				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[PrijenosAnaliticki]
				FROM
					[fin].[tblKonto]
				WHERE
					[ID] = @ID
					AND [Sifra] = @Sifra
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_GetByIDIDTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_GetByIDIDTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_GetByIDIDTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKonto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_GetByIDIDTip
(

	@ID int   ,

	@IDTip int   
)
AS


				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[PrijenosAnaliticki]
				FROM
					[fin].[tblKonto]
				WHERE
					[ID] = @ID
					AND [IDTip] = @IDTip
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_GetByAnalitickiIDSifra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_GetByAnalitickiIDSifra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_GetByAnalitickiIDSifra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKonto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_GetByAnalitickiIDSifra
(

	@Analiticki bit   ,

	@ID int   ,

	@Sifra varchar (9)  
)
AS


				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[PrijenosAnaliticki]
				FROM
					[fin].[tblKonto]
				WHERE
					[Analiticki] = @Analiticki
					AND [ID] = @ID
					AND [Sifra] = @Sifra
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_GetByIDTipID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_GetByIDTipID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_GetByIDTipID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKonto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_GetByIDTipID
(

	@IDTip int   ,

	@ID int   
)
AS


				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[PrijenosAnaliticki]
				FROM
					[fin].[tblKonto]
				WHERE
					[IDTip] = @IDTip
					AND [ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_GetByIDIDTipSifra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_GetByIDIDTipSifra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_GetByIDIDTipSifra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKonto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_GetByIDIDTipSifra
(

	@ID int   ,

	@IDTip int   ,

	@Sifra varchar (9)  
)
AS


				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[PrijenosAnaliticki]
				FROM
					[fin].[tblKonto]
				WHERE
					[ID] = @ID
					AND [IDTip] = @IDTip
					AND [Sifra] = @Sifra
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_GetByIDTipIDSifra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_GetByIDTipIDSifra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_GetByIDTipIDSifra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKonto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_GetByIDTipIDSifra
(

	@IDTip int   ,

	@ID int   ,

	@Sifra varchar (9)  
)
AS


				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[PrijenosAnaliticki]
				FROM
					[fin].[tblKonto]
				WHERE
					[IDTip] = @IDTip
					AND [ID] = @ID
					AND [Sifra] = @Sifra
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_GetBySifra procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_GetBySifra') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_GetBySifra
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKonto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_GetBySifra
(

	@Sifra varchar (9)  
)
AS


				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[PrijenosAnaliticki]
				FROM
					[fin].[tblKonto]
				WHERE
					[Sifra] = @Sifra
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKonto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[PrijenosAnaliticki]
				FROM
					[fin].[tblKonto]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKonto_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKonto_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKonto_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblKonto table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKonto_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Sifra varchar (9)  = null ,

	@Naziv nvarchar (250)  = null ,

	@Analiticki bit   = null ,

	@IDTip int   = null ,

	@IDKontoPoreza int   = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null ,

	@PrijenosAnaliticki bit   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Sifra]
	, [Naziv]
	, [Analiticki]
	, [IDTip]
	, [IDKontoPoreza]
	, [DatumOd]
	, [DatumDo]
	, [PrijenosAnaliticki]
    FROM
	[fin].[tblKonto]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Sifra] = @Sifra OR @Sifra is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Analiticki] = @Analiticki OR @Analiticki is null)
	AND ([IDTip] = @IDTip OR @IDTip is null)
	AND ([IDKontoPoreza] = @IDKontoPoreza OR @IDKontoPoreza is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
	AND ([PrijenosAnaliticki] = @PrijenosAnaliticki OR @PrijenosAnaliticki is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Sifra]
	, [Naziv]
	, [Analiticki]
	, [IDTip]
	, [IDKontoPoreza]
	, [DatumOd]
	, [DatumDo]
	, [PrijenosAnaliticki]
    FROM
	[fin].[tblKonto]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Sifra] = @Sifra AND @Sifra is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Analiticki] = @Analiticki AND @Analiticki is not null)
	OR ([IDTip] = @IDTip AND @IDTip is not null)
	OR ([IDKontoPoreza] = @IDKontoPoreza AND @IDKontoPoreza is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	OR ([PrijenosAnaliticki] = @PrijenosAnaliticki AND @PrijenosAnaliticki is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamata_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamata_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamata_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracunKamata table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamata_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[IDOrganizacija],
					[IDStatus],
					[Oznaka],
					[DateCreated],
					[DateModified],
					[IDUserCreated],
					[IDUserModified],
					[RedBr],
					[DatumObracuna],
					[DatumDospijeca]
				FROM
					[fin].[tblObracunKamata]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamata_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamata_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamata_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracunKamata table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamata_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [IDOrganizacija]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [DateCreated]'
				SET @SQL = @SQL + ', [DateModified]'
				SET @SQL = @SQL + ', [IDUserCreated]'
				SET @SQL = @SQL + ', [IDUserModified]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [DatumObracuna]'
				SET @SQL = @SQL + ', [DatumDospijeca]'
				SET @SQL = @SQL + ' FROM [fin].[tblObracunKamata]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [IDOrganizacija],'
				SET @SQL = @SQL + ' [IDStatus],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [DateCreated],'
				SET @SQL = @SQL + ' [DateModified],'
				SET @SQL = @SQL + ' [IDUserCreated],'
				SET @SQL = @SQL + ' [IDUserModified],'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [DatumObracuna],'
				SET @SQL = @SQL + ' [DatumDospijeca]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblObracunKamata]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamata_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamata_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamata_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracunKamata table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamata_Insert
(

	@ID int    OUTPUT,

	@IDKlijent int   ,

	@IDOrganizacija int   ,

	@IDStatus int   ,

	@Oznaka nvarchar (50)  ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@RedBr int   ,

	@DatumObracuna datetime   ,

	@DatumDospijeca datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblObracunKamata]
					(
					[IDKlijent]
					,[IDOrganizacija]
					,[IDStatus]
					,[Oznaka]
					,[DateCreated]
					,[DateModified]
					,[IDUserCreated]
					,[IDUserModified]
					,[RedBr]
					,[DatumObracuna]
					,[DatumDospijeca]
					)
				VALUES
					(
					@IDKlijent
					,@IDOrganizacija
					,@IDStatus
					,@Oznaka
					,@DateCreated
					,@DateModified
					,@IDUserCreated
					,@IDUserModified
					,@RedBr
					,@DatumObracuna
					,@DatumDospijeca
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamata_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamata_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamata_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracunKamata table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamata_Update
(

	@ID int   ,

	@IDKlijent int   ,

	@IDOrganizacija int   ,

	@IDStatus int   ,

	@Oznaka nvarchar (50)  ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@RedBr int   ,

	@DatumObracuna datetime   ,

	@DatumDospijeca datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblObracunKamata]
				SET
					[IDKlijent] = @IDKlijent
					,[IDOrganizacija] = @IDOrganizacija
					,[IDStatus] = @IDStatus
					,[Oznaka] = @Oznaka
					,[DateCreated] = @DateCreated
					,[DateModified] = @DateModified
					,[IDUserCreated] = @IDUserCreated
					,[IDUserModified] = @IDUserModified
					,[RedBr] = @RedBr
					,[DatumObracuna] = @DatumObracuna
					,[DatumDospijeca] = @DatumDospijeca
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamata_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamata_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamata_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracunKamata table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamata_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblObracunKamata] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamata_GetByIDUserModified procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamata_GetByIDUserModified') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamata_GetByIDUserModified
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamata table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamata_GetByIDUserModified
(

	@IDUserModified int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[IDOrganizacija],
					[IDStatus],
					[Oznaka],
					[DateCreated],
					[DateModified],
					[IDUserCreated],
					[IDUserModified],
					[RedBr],
					[DatumObracuna],
					[DatumDospijeca]
				FROM
					[fin].[tblObracunKamata]
				WHERE
					[IDUserModified] = @IDUserModified
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamata_GetByIDKlijent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamata_GetByIDKlijent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamata_GetByIDKlijent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamata table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamata_GetByIDKlijent
(

	@IDKlijent int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[IDOrganizacija],
					[IDStatus],
					[Oznaka],
					[DateCreated],
					[DateModified],
					[IDUserCreated],
					[IDUserModified],
					[RedBr],
					[DatumObracuna],
					[DatumDospijeca]
				FROM
					[fin].[tblObracunKamata]
				WHERE
					[IDKlijent] = @IDKlijent
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamata_GetByIDOrganizacija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamata_GetByIDOrganizacija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamata_GetByIDOrganizacija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamata table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamata_GetByIDOrganizacija
(

	@IDOrganizacija int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[IDOrganizacija],
					[IDStatus],
					[Oznaka],
					[DateCreated],
					[DateModified],
					[IDUserCreated],
					[IDUserModified],
					[RedBr],
					[DatumObracuna],
					[DatumDospijeca]
				FROM
					[fin].[tblObracunKamata]
				WHERE
					[IDOrganizacija] = @IDOrganizacija
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamata_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamata_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamata_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamata table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamata_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDKlijent],
					[IDOrganizacija],
					[IDStatus],
					[Oznaka],
					[DateCreated],
					[DateModified],
					[IDUserCreated],
					[IDUserModified],
					[RedBr],
					[DatumObracuna],
					[DatumDospijeca]
				FROM
					[fin].[tblObracunKamata]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamata_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamata_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamata_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracunKamata table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamata_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDKlijent int   = null ,

	@IDOrganizacija int   = null ,

	@IDStatus int   = null ,

	@Oznaka nvarchar (50)  = null ,

	@DateCreated datetime   = null ,

	@DateModified datetime   = null ,

	@IDUserCreated int   = null ,

	@IDUserModified int   = null ,

	@RedBr int   = null ,

	@DatumObracuna datetime   = null ,

	@DatumDospijeca datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDKlijent]
	, [IDOrganizacija]
	, [IDStatus]
	, [Oznaka]
	, [DateCreated]
	, [DateModified]
	, [IDUserCreated]
	, [IDUserModified]
	, [RedBr]
	, [DatumObracuna]
	, [DatumDospijeca]
    FROM
	[fin].[tblObracunKamata]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDKlijent] = @IDKlijent OR @IDKlijent is null)
	AND ([IDOrganizacija] = @IDOrganizacija OR @IDOrganizacija is null)
	AND ([IDStatus] = @IDStatus OR @IDStatus is null)
	AND ([Oznaka] = @Oznaka OR @Oznaka is null)
	AND ([DateCreated] = @DateCreated OR @DateCreated is null)
	AND ([DateModified] = @DateModified OR @DateModified is null)
	AND ([IDUserCreated] = @IDUserCreated OR @IDUserCreated is null)
	AND ([IDUserModified] = @IDUserModified OR @IDUserModified is null)
	AND ([RedBr] = @RedBr OR @RedBr is null)
	AND ([DatumObracuna] = @DatumObracuna OR @DatumObracuna is null)
	AND ([DatumDospijeca] = @DatumDospijeca OR @DatumDospijeca is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDKlijent]
	, [IDOrganizacija]
	, [IDStatus]
	, [Oznaka]
	, [DateCreated]
	, [DateModified]
	, [IDUserCreated]
	, [IDUserModified]
	, [RedBr]
	, [DatumObracuna]
	, [DatumDospijeca]
    FROM
	[fin].[tblObracunKamata]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDKlijent] = @IDKlijent AND @IDKlijent is not null)
	OR ([IDOrganizacija] = @IDOrganizacija AND @IDOrganizacija is not null)
	OR ([IDStatus] = @IDStatus AND @IDStatus is not null)
	OR ([Oznaka] = @Oznaka AND @Oznaka is not null)
	OR ([DateCreated] = @DateCreated AND @DateCreated is not null)
	OR ([DateModified] = @DateModified AND @DateModified is not null)
	OR ([IDUserCreated] = @IDUserCreated AND @IDUserCreated is not null)
	OR ([IDUserModified] = @IDUserModified AND @IDUserModified is not null)
	OR ([RedBr] = @RedBr AND @RedBr is not null)
	OR ([DatumObracuna] = @DatumObracuna AND @DatumObracuna is not null)
	OR ([DatumDospijeca] = @DatumDospijeca AND @DatumDospijeca is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinPlacanja_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinPlacanja_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinPlacanja_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblNacinPlacanja table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinPlacanja_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[PrikazKalkulatora]
				FROM
					[dbo].[tblNacinPlacanja]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinPlacanja_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinPlacanja_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinPlacanja_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblNacinPlacanja table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinPlacanja_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [PrikazKalkulatora]'
				SET @SQL = @SQL + ' FROM [dbo].[tblNacinPlacanja]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [PrikazKalkulatora]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblNacinPlacanja]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinPlacanja_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinPlacanja_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinPlacanja_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblNacinPlacanja table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinPlacanja_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (150)  ,

	@PrikazKalkulatora bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblNacinPlacanja]
					(
					[Naziv]
					,[PrikazKalkulatora]
					)
				VALUES
					(
					@Naziv
					,@PrikazKalkulatora
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinPlacanja_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinPlacanja_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinPlacanja_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblNacinPlacanja table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinPlacanja_Update
(

	@ID int   ,

	@Naziv nvarchar (150)  ,

	@PrikazKalkulatora bit   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblNacinPlacanja]
				SET
					[Naziv] = @Naziv
					,[PrikazKalkulatora] = @PrikazKalkulatora
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinPlacanja_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinPlacanja_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinPlacanja_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblNacinPlacanja table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinPlacanja_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblNacinPlacanja] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinPlacanja_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinPlacanja_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinPlacanja_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblNacinPlacanja table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinPlacanja_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[PrikazKalkulatora]
				FROM
					[dbo].[tblNacinPlacanja]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblNacinPlacanja_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblNacinPlacanja_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblNacinPlacanja_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblNacinPlacanja table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblNacinPlacanja_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (150)  = null ,

	@PrikazKalkulatora bit   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [PrikazKalkulatora]
    FROM
	[dbo].[tblNacinPlacanja]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([PrikazKalkulatora] = @PrikazKalkulatora OR @PrikazKalkulatora is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [PrikazKalkulatora]
    FROM
	[dbo].[tblNacinPlacanja]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([PrikazKalkulatora] = @PrikazKalkulatora AND @PrikazKalkulatora is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsoba_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsoba_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsoba_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracunOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsoba_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[BrutoIznosZaRazdoblje],
					[BrutoSatnica],
					[ProsjecnaBruto6Mjeseci],
					[ProsjecnaNeto6Mjeseci],
					[IDObracun],
					[OsobniOdbitak],
					[MaksPorezneOlaksice],
					[UkBruto],
					[UkMIO1Iznos],
					[UkMIO1PovecaniStazIznos],
					[UkMIO2Iznos],
					[MIO2PovecaniStazIznos],
					[IznosPoreznihOlaksica],
					[PoreznaOsnovica],
					[Porez15],
					[Porez25],
					[Porez35],
					[Porez45],
					[UkPorez],
					[Prirez],
					[PrirezIznos],
					[IDMjestoPrirez],
					[Zdravstveno],
					[Zaposljavanje],
					[Nezgoda],
					[PosPorez],
					[ZapOsobaSInvaliditetom],
					[ZapOsobaSInvaliditetomIznos],
					[NetoPredPorezIPrirez],
					[NetoPredPosPorez],
					[NetoIsplata],
					[ZdravstvenoZaInozemstvo],
					[UkObustave],
					[UkNaknade],
					[PosebniPorezPostotak],
					[NetoIsplataNakonObustavaNaknada],
					[MIO1Postotak],
					[MIO2Postotak],
					[UkIznosBezDoprinosa],
					[DatumObracunaOd],
					[DatumObracunaDo],
					[DatumDospijeca]
				FROM
					[pla].[tblObracunOsoba]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsoba_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsoba_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsoba_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracunOsoba table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsoba_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [BrutoIznosZaRazdoblje]'
				SET @SQL = @SQL + ', [BrutoSatnica]'
				SET @SQL = @SQL + ', [ProsjecnaBruto6Mjeseci]'
				SET @SQL = @SQL + ', [ProsjecnaNeto6Mjeseci]'
				SET @SQL = @SQL + ', [IDObracun]'
				SET @SQL = @SQL + ', [OsobniOdbitak]'
				SET @SQL = @SQL + ', [MaksPorezneOlaksice]'
				SET @SQL = @SQL + ', [UkBruto]'
				SET @SQL = @SQL + ', [UkMIO1Iznos]'
				SET @SQL = @SQL + ', [UkMIO1PovecaniStazIznos]'
				SET @SQL = @SQL + ', [UkMIO2Iznos]'
				SET @SQL = @SQL + ', [MIO2PovecaniStazIznos]'
				SET @SQL = @SQL + ', [IznosPoreznihOlaksica]'
				SET @SQL = @SQL + ', [PoreznaOsnovica]'
				SET @SQL = @SQL + ', [Porez15]'
				SET @SQL = @SQL + ', [Porez25]'
				SET @SQL = @SQL + ', [Porez35]'
				SET @SQL = @SQL + ', [Porez45]'
				SET @SQL = @SQL + ', [UkPorez]'
				SET @SQL = @SQL + ', [Prirez]'
				SET @SQL = @SQL + ', [PrirezIznos]'
				SET @SQL = @SQL + ', [IDMjestoPrirez]'
				SET @SQL = @SQL + ', [Zdravstveno]'
				SET @SQL = @SQL + ', [Zaposljavanje]'
				SET @SQL = @SQL + ', [Nezgoda]'
				SET @SQL = @SQL + ', [PosPorez]'
				SET @SQL = @SQL + ', [ZapOsobaSInvaliditetom]'
				SET @SQL = @SQL + ', [ZapOsobaSInvaliditetomIznos]'
				SET @SQL = @SQL + ', [NetoPredPorezIPrirez]'
				SET @SQL = @SQL + ', [NetoPredPosPorez]'
				SET @SQL = @SQL + ', [NetoIsplata]'
				SET @SQL = @SQL + ', [ZdravstvenoZaInozemstvo]'
				SET @SQL = @SQL + ', [UkObustave]'
				SET @SQL = @SQL + ', [UkNaknade]'
				SET @SQL = @SQL + ', [PosebniPorezPostotak]'
				SET @SQL = @SQL + ', [NetoIsplataNakonObustavaNaknada]'
				SET @SQL = @SQL + ', [MIO1Postotak]'
				SET @SQL = @SQL + ', [MIO2Postotak]'
				SET @SQL = @SQL + ', [UkIznosBezDoprinosa]'
				SET @SQL = @SQL + ', [DatumObracunaOd]'
				SET @SQL = @SQL + ', [DatumObracunaDo]'
				SET @SQL = @SQL + ', [DatumDospijeca]'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunOsoba]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [BrutoIznosZaRazdoblje],'
				SET @SQL = @SQL + ' [BrutoSatnica],'
				SET @SQL = @SQL + ' [ProsjecnaBruto6Mjeseci],'
				SET @SQL = @SQL + ' [ProsjecnaNeto6Mjeseci],'
				SET @SQL = @SQL + ' [IDObracun],'
				SET @SQL = @SQL + ' [OsobniOdbitak],'
				SET @SQL = @SQL + ' [MaksPorezneOlaksice],'
				SET @SQL = @SQL + ' [UkBruto],'
				SET @SQL = @SQL + ' [UkMIO1Iznos],'
				SET @SQL = @SQL + ' [UkMIO1PovecaniStazIznos],'
				SET @SQL = @SQL + ' [UkMIO2Iznos],'
				SET @SQL = @SQL + ' [MIO2PovecaniStazIznos],'
				SET @SQL = @SQL + ' [IznosPoreznihOlaksica],'
				SET @SQL = @SQL + ' [PoreznaOsnovica],'
				SET @SQL = @SQL + ' [Porez15],'
				SET @SQL = @SQL + ' [Porez25],'
				SET @SQL = @SQL + ' [Porez35],'
				SET @SQL = @SQL + ' [Porez45],'
				SET @SQL = @SQL + ' [UkPorez],'
				SET @SQL = @SQL + ' [Prirez],'
				SET @SQL = @SQL + ' [PrirezIznos],'
				SET @SQL = @SQL + ' [IDMjestoPrirez],'
				SET @SQL = @SQL + ' [Zdravstveno],'
				SET @SQL = @SQL + ' [Zaposljavanje],'
				SET @SQL = @SQL + ' [Nezgoda],'
				SET @SQL = @SQL + ' [PosPorez],'
				SET @SQL = @SQL + ' [ZapOsobaSInvaliditetom],'
				SET @SQL = @SQL + ' [ZapOsobaSInvaliditetomIznos],'
				SET @SQL = @SQL + ' [NetoPredPorezIPrirez],'
				SET @SQL = @SQL + ' [NetoPredPosPorez],'
				SET @SQL = @SQL + ' [NetoIsplata],'
				SET @SQL = @SQL + ' [ZdravstvenoZaInozemstvo],'
				SET @SQL = @SQL + ' [UkObustave],'
				SET @SQL = @SQL + ' [UkNaknade],'
				SET @SQL = @SQL + ' [PosebniPorezPostotak],'
				SET @SQL = @SQL + ' [NetoIsplataNakonObustavaNaknada],'
				SET @SQL = @SQL + ' [MIO1Postotak],'
				SET @SQL = @SQL + ' [MIO2Postotak],'
				SET @SQL = @SQL + ' [UkIznosBezDoprinosa],'
				SET @SQL = @SQL + ' [DatumObracunaOd],'
				SET @SQL = @SQL + ' [DatumObracunaDo],'
				SET @SQL = @SQL + ' [DatumDospijeca]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunOsoba]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsoba_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsoba_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsoba_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracunOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsoba_Insert
(

	@ID int    OUTPUT,

	@IDOsoba int   ,

	@BrutoIznosZaRazdoblje money   ,

	@BrutoSatnica money   ,

	@ProsjecnaBruto6Mjeseci money   ,

	@ProsjecnaNeto6Mjeseci money   ,

	@IDObracun int   ,

	@OsobniOdbitak real   ,

	@MaksPorezneOlaksice money   ,

	@UkBruto money   ,

	@UkMIO1Iznos money   ,

	@UkMIO1PovecaniStazIznos money   ,

	@UkMIO2Iznos money   ,

	@MIO2PovecaniStazIznos money   ,

	@IznosPoreznihOlaksica money   ,

	@PoreznaOsnovica money   ,

	@Porez15 money   ,

	@Porez25 money   ,

	@Porez35 money   ,

	@Porez45 money   ,

	@UkPorez money   ,

	@Prirez money   ,

	@PrirezIznos money   ,

	@IDMjestoPrirez int   ,

	@Zdravstveno money   ,

	@Zaposljavanje money   ,

	@Nezgoda money   ,

	@PosPorez money   ,

	@ZapOsobaSInvaliditetom money   ,

	@ZapOsobaSInvaliditetomIznos money   ,

	@NetoPredPorezIPrirez money   ,

	@NetoPredPosPorez money   ,

	@NetoIsplata money   ,

	@ZdravstvenoZaInozemstvo money   ,

	@UkObustave money   ,

	@UkNaknade money   ,

	@PosebniPorezPostotak money   ,

	@NetoIsplataNakonObustavaNaknada money   ,

	@MIO1Postotak money   ,

	@MIO2Postotak money   ,

	@UkIznosBezDoprinosa money   ,

	@DatumObracunaOd datetime   ,

	@DatumObracunaDo datetime   ,

	@DatumDospijeca datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblObracunOsoba]
					(
					[IDOsoba]
					,[BrutoIznosZaRazdoblje]
					,[BrutoSatnica]
					,[ProsjecnaBruto6Mjeseci]
					,[ProsjecnaNeto6Mjeseci]
					,[IDObracun]
					,[OsobniOdbitak]
					,[MaksPorezneOlaksice]
					,[UkBruto]
					,[UkMIO1Iznos]
					,[UkMIO1PovecaniStazIznos]
					,[UkMIO2Iznos]
					,[MIO2PovecaniStazIznos]
					,[IznosPoreznihOlaksica]
					,[PoreznaOsnovica]
					,[Porez15]
					,[Porez25]
					,[Porez35]
					,[Porez45]
					,[UkPorez]
					,[Prirez]
					,[PrirezIznos]
					,[IDMjestoPrirez]
					,[Zdravstveno]
					,[Zaposljavanje]
					,[Nezgoda]
					,[PosPorez]
					,[ZapOsobaSInvaliditetom]
					,[ZapOsobaSInvaliditetomIznos]
					,[NetoPredPorezIPrirez]
					,[NetoPredPosPorez]
					,[NetoIsplata]
					,[ZdravstvenoZaInozemstvo]
					,[UkObustave]
					,[UkNaknade]
					,[PosebniPorezPostotak]
					,[NetoIsplataNakonObustavaNaknada]
					,[MIO1Postotak]
					,[MIO2Postotak]
					,[UkIznosBezDoprinosa]
					,[DatumObracunaOd]
					,[DatumObracunaDo]
					,[DatumDospijeca]
					)
				VALUES
					(
					@IDOsoba
					,@BrutoIznosZaRazdoblje
					,@BrutoSatnica
					,@ProsjecnaBruto6Mjeseci
					,@ProsjecnaNeto6Mjeseci
					,@IDObracun
					,@OsobniOdbitak
					,@MaksPorezneOlaksice
					,@UkBruto
					,@UkMIO1Iznos
					,@UkMIO1PovecaniStazIznos
					,@UkMIO2Iznos
					,@MIO2PovecaniStazIznos
					,@IznosPoreznihOlaksica
					,@PoreznaOsnovica
					,@Porez15
					,@Porez25
					,@Porez35
					,@Porez45
					,@UkPorez
					,@Prirez
					,@PrirezIznos
					,@IDMjestoPrirez
					,@Zdravstveno
					,@Zaposljavanje
					,@Nezgoda
					,@PosPorez
					,@ZapOsobaSInvaliditetom
					,@ZapOsobaSInvaliditetomIznos
					,@NetoPredPorezIPrirez
					,@NetoPredPosPorez
					,@NetoIsplata
					,@ZdravstvenoZaInozemstvo
					,@UkObustave
					,@UkNaknade
					,@PosebniPorezPostotak
					,@NetoIsplataNakonObustavaNaknada
					,@MIO1Postotak
					,@MIO2Postotak
					,@UkIznosBezDoprinosa
					,@DatumObracunaOd
					,@DatumObracunaDo
					,@DatumDospijeca
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsoba_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsoba_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsoba_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracunOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsoba_Update
(

	@ID int   ,

	@IDOsoba int   ,

	@BrutoIznosZaRazdoblje money   ,

	@BrutoSatnica money   ,

	@ProsjecnaBruto6Mjeseci money   ,

	@ProsjecnaNeto6Mjeseci money   ,

	@IDObracun int   ,

	@OsobniOdbitak real   ,

	@MaksPorezneOlaksice money   ,

	@UkBruto money   ,

	@UkMIO1Iznos money   ,

	@UkMIO1PovecaniStazIznos money   ,

	@UkMIO2Iznos money   ,

	@MIO2PovecaniStazIznos money   ,

	@IznosPoreznihOlaksica money   ,

	@PoreznaOsnovica money   ,

	@Porez15 money   ,

	@Porez25 money   ,

	@Porez35 money   ,

	@Porez45 money   ,

	@UkPorez money   ,

	@Prirez money   ,

	@PrirezIznos money   ,

	@IDMjestoPrirez int   ,

	@Zdravstveno money   ,

	@Zaposljavanje money   ,

	@Nezgoda money   ,

	@PosPorez money   ,

	@ZapOsobaSInvaliditetom money   ,

	@ZapOsobaSInvaliditetomIznos money   ,

	@NetoPredPorezIPrirez money   ,

	@NetoPredPosPorez money   ,

	@NetoIsplata money   ,

	@ZdravstvenoZaInozemstvo money   ,

	@UkObustave money   ,

	@UkNaknade money   ,

	@PosebniPorezPostotak money   ,

	@NetoIsplataNakonObustavaNaknada money   ,

	@MIO1Postotak money   ,

	@MIO2Postotak money   ,

	@UkIznosBezDoprinosa money   ,

	@DatumObracunaOd datetime   ,

	@DatumObracunaDo datetime   ,

	@DatumDospijeca datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblObracunOsoba]
				SET
					[IDOsoba] = @IDOsoba
					,[BrutoIznosZaRazdoblje] = @BrutoIznosZaRazdoblje
					,[BrutoSatnica] = @BrutoSatnica
					,[ProsjecnaBruto6Mjeseci] = @ProsjecnaBruto6Mjeseci
					,[ProsjecnaNeto6Mjeseci] = @ProsjecnaNeto6Mjeseci
					,[IDObracun] = @IDObracun
					,[OsobniOdbitak] = @OsobniOdbitak
					,[MaksPorezneOlaksice] = @MaksPorezneOlaksice
					,[UkBruto] = @UkBruto
					,[UkMIO1Iznos] = @UkMIO1Iznos
					,[UkMIO1PovecaniStazIznos] = @UkMIO1PovecaniStazIznos
					,[UkMIO2Iznos] = @UkMIO2Iznos
					,[MIO2PovecaniStazIznos] = @MIO2PovecaniStazIznos
					,[IznosPoreznihOlaksica] = @IznosPoreznihOlaksica
					,[PoreznaOsnovica] = @PoreznaOsnovica
					,[Porez15] = @Porez15
					,[Porez25] = @Porez25
					,[Porez35] = @Porez35
					,[Porez45] = @Porez45
					,[UkPorez] = @UkPorez
					,[Prirez] = @Prirez
					,[PrirezIznos] = @PrirezIznos
					,[IDMjestoPrirez] = @IDMjestoPrirez
					,[Zdravstveno] = @Zdravstveno
					,[Zaposljavanje] = @Zaposljavanje
					,[Nezgoda] = @Nezgoda
					,[PosPorez] = @PosPorez
					,[ZapOsobaSInvaliditetom] = @ZapOsobaSInvaliditetom
					,[ZapOsobaSInvaliditetomIznos] = @ZapOsobaSInvaliditetomIznos
					,[NetoPredPorezIPrirez] = @NetoPredPorezIPrirez
					,[NetoPredPosPorez] = @NetoPredPosPorez
					,[NetoIsplata] = @NetoIsplata
					,[ZdravstvenoZaInozemstvo] = @ZdravstvenoZaInozemstvo
					,[UkObustave] = @UkObustave
					,[UkNaknade] = @UkNaknade
					,[PosebniPorezPostotak] = @PosebniPorezPostotak
					,[NetoIsplataNakonObustavaNaknada] = @NetoIsplataNakonObustavaNaknada
					,[MIO1Postotak] = @MIO1Postotak
					,[MIO2Postotak] = @MIO2Postotak
					,[UkIznosBezDoprinosa] = @UkIznosBezDoprinosa
					,[DatumObracunaOd] = @DatumObracunaOd
					,[DatumObracunaDo] = @DatumObracunaDo
					,[DatumDospijeca] = @DatumDospijeca
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsoba_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsoba_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsoba_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracunOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsoba_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblObracunOsoba] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsoba_GetByIDObracun procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsoba_GetByIDObracun') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsoba_GetByIDObracun
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsoba table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsoba_GetByIDObracun
(

	@IDObracun int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[BrutoIznosZaRazdoblje],
					[BrutoSatnica],
					[ProsjecnaBruto6Mjeseci],
					[ProsjecnaNeto6Mjeseci],
					[IDObracun],
					[OsobniOdbitak],
					[MaksPorezneOlaksice],
					[UkBruto],
					[UkMIO1Iznos],
					[UkMIO1PovecaniStazIznos],
					[UkMIO2Iznos],
					[MIO2PovecaniStazIznos],
					[IznosPoreznihOlaksica],
					[PoreznaOsnovica],
					[Porez15],
					[Porez25],
					[Porez35],
					[Porez45],
					[UkPorez],
					[Prirez],
					[PrirezIznos],
					[IDMjestoPrirez],
					[Zdravstveno],
					[Zaposljavanje],
					[Nezgoda],
					[PosPorez],
					[ZapOsobaSInvaliditetom],
					[ZapOsobaSInvaliditetomIznos],
					[NetoPredPorezIPrirez],
					[NetoPredPosPorez],
					[NetoIsplata],
					[ZdravstvenoZaInozemstvo],
					[UkObustave],
					[UkNaknade],
					[PosebniPorezPostotak],
					[NetoIsplataNakonObustavaNaknada],
					[MIO1Postotak],
					[MIO2Postotak],
					[UkIznosBezDoprinosa],
					[DatumObracunaOd],
					[DatumObracunaDo],
					[DatumDospijeca]
				FROM
					[pla].[tblObracunOsoba]
				WHERE
					[IDObracun] = @IDObracun
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsoba_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsoba_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsoba_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsoba table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsoba_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[BrutoIznosZaRazdoblje],
					[BrutoSatnica],
					[ProsjecnaBruto6Mjeseci],
					[ProsjecnaNeto6Mjeseci],
					[IDObracun],
					[OsobniOdbitak],
					[MaksPorezneOlaksice],
					[UkBruto],
					[UkMIO1Iznos],
					[UkMIO1PovecaniStazIznos],
					[UkMIO2Iznos],
					[MIO2PovecaniStazIznos],
					[IznosPoreznihOlaksica],
					[PoreznaOsnovica],
					[Porez15],
					[Porez25],
					[Porez35],
					[Porez45],
					[UkPorez],
					[Prirez],
					[PrirezIznos],
					[IDMjestoPrirez],
					[Zdravstveno],
					[Zaposljavanje],
					[Nezgoda],
					[PosPorez],
					[ZapOsobaSInvaliditetom],
					[ZapOsobaSInvaliditetomIznos],
					[NetoPredPorezIPrirez],
					[NetoPredPosPorez],
					[NetoIsplata],
					[ZdravstvenoZaInozemstvo],
					[UkObustave],
					[UkNaknade],
					[PosebniPorezPostotak],
					[NetoIsplataNakonObustavaNaknada],
					[MIO1Postotak],
					[MIO2Postotak],
					[UkIznosBezDoprinosa],
					[DatumObracunaOd],
					[DatumObracunaDo],
					[DatumDospijeca]
				FROM
					[pla].[tblObracunOsoba]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsoba_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsoba_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsoba_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsoba table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsoba_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOsoba],
					[BrutoIznosZaRazdoblje],
					[BrutoSatnica],
					[ProsjecnaBruto6Mjeseci],
					[ProsjecnaNeto6Mjeseci],
					[IDObracun],
					[OsobniOdbitak],
					[MaksPorezneOlaksice],
					[UkBruto],
					[UkMIO1Iznos],
					[UkMIO1PovecaniStazIznos],
					[UkMIO2Iznos],
					[MIO2PovecaniStazIznos],
					[IznosPoreznihOlaksica],
					[PoreznaOsnovica],
					[Porez15],
					[Porez25],
					[Porez35],
					[Porez45],
					[UkPorez],
					[Prirez],
					[PrirezIznos],
					[IDMjestoPrirez],
					[Zdravstveno],
					[Zaposljavanje],
					[Nezgoda],
					[PosPorez],
					[ZapOsobaSInvaliditetom],
					[ZapOsobaSInvaliditetomIznos],
					[NetoPredPorezIPrirez],
					[NetoPredPosPorez],
					[NetoIsplata],
					[ZdravstvenoZaInozemstvo],
					[UkObustave],
					[UkNaknade],
					[PosebniPorezPostotak],
					[NetoIsplataNakonObustavaNaknada],
					[MIO1Postotak],
					[MIO2Postotak],
					[UkIznosBezDoprinosa],
					[DatumObracunaOd],
					[DatumObracunaDo],
					[DatumDospijeca]
				FROM
					[pla].[tblObracunOsoba]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsoba_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsoba_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsoba_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracunOsoba table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsoba_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOsoba int   = null ,

	@BrutoIznosZaRazdoblje money   = null ,

	@BrutoSatnica money   = null ,

	@ProsjecnaBruto6Mjeseci money   = null ,

	@ProsjecnaNeto6Mjeseci money   = null ,

	@IDObracun int   = null ,

	@OsobniOdbitak real   = null ,

	@MaksPorezneOlaksice money   = null ,

	@UkBruto money   = null ,

	@UkMIO1Iznos money   = null ,

	@UkMIO1PovecaniStazIznos money   = null ,

	@UkMIO2Iznos money   = null ,

	@MIO2PovecaniStazIznos money   = null ,

	@IznosPoreznihOlaksica money   = null ,

	@PoreznaOsnovica money   = null ,

	@Porez15 money   = null ,

	@Porez25 money   = null ,

	@Porez35 money   = null ,

	@Porez45 money   = null ,

	@UkPorez money   = null ,

	@Prirez money   = null ,

	@PrirezIznos money   = null ,

	@IDMjestoPrirez int   = null ,

	@Zdravstveno money   = null ,

	@Zaposljavanje money   = null ,

	@Nezgoda money   = null ,

	@PosPorez money   = null ,

	@ZapOsobaSInvaliditetom money   = null ,

	@ZapOsobaSInvaliditetomIznos money   = null ,

	@NetoPredPorezIPrirez money   = null ,

	@NetoPredPosPorez money   = null ,

	@NetoIsplata money   = null ,

	@ZdravstvenoZaInozemstvo money   = null ,

	@UkObustave money   = null ,

	@UkNaknade money   = null ,

	@PosebniPorezPostotak money   = null ,

	@NetoIsplataNakonObustavaNaknada money   = null ,

	@MIO1Postotak money   = null ,

	@MIO2Postotak money   = null ,

	@UkIznosBezDoprinosa money   = null ,

	@DatumObracunaOd datetime   = null ,

	@DatumObracunaDo datetime   = null ,

	@DatumDospijeca datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOsoba]
	, [BrutoIznosZaRazdoblje]
	, [BrutoSatnica]
	, [ProsjecnaBruto6Mjeseci]
	, [ProsjecnaNeto6Mjeseci]
	, [IDObracun]
	, [OsobniOdbitak]
	, [MaksPorezneOlaksice]
	, [UkBruto]
	, [UkMIO1Iznos]
	, [UkMIO1PovecaniStazIznos]
	, [UkMIO2Iznos]
	, [MIO2PovecaniStazIznos]
	, [IznosPoreznihOlaksica]
	, [PoreznaOsnovica]
	, [Porez15]
	, [Porez25]
	, [Porez35]
	, [Porez45]
	, [UkPorez]
	, [Prirez]
	, [PrirezIznos]
	, [IDMjestoPrirez]
	, [Zdravstveno]
	, [Zaposljavanje]
	, [Nezgoda]
	, [PosPorez]
	, [ZapOsobaSInvaliditetom]
	, [ZapOsobaSInvaliditetomIznos]
	, [NetoPredPorezIPrirez]
	, [NetoPredPosPorez]
	, [NetoIsplata]
	, [ZdravstvenoZaInozemstvo]
	, [UkObustave]
	, [UkNaknade]
	, [PosebniPorezPostotak]
	, [NetoIsplataNakonObustavaNaknada]
	, [MIO1Postotak]
	, [MIO2Postotak]
	, [UkIznosBezDoprinosa]
	, [DatumObracunaOd]
	, [DatumObracunaDo]
	, [DatumDospijeca]
    FROM
	[pla].[tblObracunOsoba]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([BrutoIznosZaRazdoblje] = @BrutoIznosZaRazdoblje OR @BrutoIznosZaRazdoblje is null)
	AND ([BrutoSatnica] = @BrutoSatnica OR @BrutoSatnica is null)
	AND ([ProsjecnaBruto6Mjeseci] = @ProsjecnaBruto6Mjeseci OR @ProsjecnaBruto6Mjeseci is null)
	AND ([ProsjecnaNeto6Mjeseci] = @ProsjecnaNeto6Mjeseci OR @ProsjecnaNeto6Mjeseci is null)
	AND ([IDObracun] = @IDObracun OR @IDObracun is null)
	AND ([OsobniOdbitak] = @OsobniOdbitak OR @OsobniOdbitak is null)
	AND ([MaksPorezneOlaksice] = @MaksPorezneOlaksice OR @MaksPorezneOlaksice is null)
	AND ([UkBruto] = @UkBruto OR @UkBruto is null)
	AND ([UkMIO1Iznos] = @UkMIO1Iznos OR @UkMIO1Iznos is null)
	AND ([UkMIO1PovecaniStazIznos] = @UkMIO1PovecaniStazIznos OR @UkMIO1PovecaniStazIznos is null)
	AND ([UkMIO2Iznos] = @UkMIO2Iznos OR @UkMIO2Iznos is null)
	AND ([MIO2PovecaniStazIznos] = @MIO2PovecaniStazIznos OR @MIO2PovecaniStazIznos is null)
	AND ([IznosPoreznihOlaksica] = @IznosPoreznihOlaksica OR @IznosPoreznihOlaksica is null)
	AND ([PoreznaOsnovica] = @PoreznaOsnovica OR @PoreznaOsnovica is null)
	AND ([Porez15] = @Porez15 OR @Porez15 is null)
	AND ([Porez25] = @Porez25 OR @Porez25 is null)
	AND ([Porez35] = @Porez35 OR @Porez35 is null)
	AND ([Porez45] = @Porez45 OR @Porez45 is null)
	AND ([UkPorez] = @UkPorez OR @UkPorez is null)
	AND ([Prirez] = @Prirez OR @Prirez is null)
	AND ([PrirezIznos] = @PrirezIznos OR @PrirezIznos is null)
	AND ([IDMjestoPrirez] = @IDMjestoPrirez OR @IDMjestoPrirez is null)
	AND ([Zdravstveno] = @Zdravstveno OR @Zdravstveno is null)
	AND ([Zaposljavanje] = @Zaposljavanje OR @Zaposljavanje is null)
	AND ([Nezgoda] = @Nezgoda OR @Nezgoda is null)
	AND ([PosPorez] = @PosPorez OR @PosPorez is null)
	AND ([ZapOsobaSInvaliditetom] = @ZapOsobaSInvaliditetom OR @ZapOsobaSInvaliditetom is null)
	AND ([ZapOsobaSInvaliditetomIznos] = @ZapOsobaSInvaliditetomIznos OR @ZapOsobaSInvaliditetomIznos is null)
	AND ([NetoPredPorezIPrirez] = @NetoPredPorezIPrirez OR @NetoPredPorezIPrirez is null)
	AND ([NetoPredPosPorez] = @NetoPredPosPorez OR @NetoPredPosPorez is null)
	AND ([NetoIsplata] = @NetoIsplata OR @NetoIsplata is null)
	AND ([ZdravstvenoZaInozemstvo] = @ZdravstvenoZaInozemstvo OR @ZdravstvenoZaInozemstvo is null)
	AND ([UkObustave] = @UkObustave OR @UkObustave is null)
	AND ([UkNaknade] = @UkNaknade OR @UkNaknade is null)
	AND ([PosebniPorezPostotak] = @PosebniPorezPostotak OR @PosebniPorezPostotak is null)
	AND ([NetoIsplataNakonObustavaNaknada] = @NetoIsplataNakonObustavaNaknada OR @NetoIsplataNakonObustavaNaknada is null)
	AND ([MIO1Postotak] = @MIO1Postotak OR @MIO1Postotak is null)
	AND ([MIO2Postotak] = @MIO2Postotak OR @MIO2Postotak is null)
	AND ([UkIznosBezDoprinosa] = @UkIznosBezDoprinosa OR @UkIznosBezDoprinosa is null)
	AND ([DatumObracunaOd] = @DatumObracunaOd OR @DatumObracunaOd is null)
	AND ([DatumObracunaDo] = @DatumObracunaDo OR @DatumObracunaDo is null)
	AND ([DatumDospijeca] = @DatumDospijeca OR @DatumDospijeca is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOsoba]
	, [BrutoIznosZaRazdoblje]
	, [BrutoSatnica]
	, [ProsjecnaBruto6Mjeseci]
	, [ProsjecnaNeto6Mjeseci]
	, [IDObracun]
	, [OsobniOdbitak]
	, [MaksPorezneOlaksice]
	, [UkBruto]
	, [UkMIO1Iznos]
	, [UkMIO1PovecaniStazIznos]
	, [UkMIO2Iznos]
	, [MIO2PovecaniStazIznos]
	, [IznosPoreznihOlaksica]
	, [PoreznaOsnovica]
	, [Porez15]
	, [Porez25]
	, [Porez35]
	, [Porez45]
	, [UkPorez]
	, [Prirez]
	, [PrirezIznos]
	, [IDMjestoPrirez]
	, [Zdravstveno]
	, [Zaposljavanje]
	, [Nezgoda]
	, [PosPorez]
	, [ZapOsobaSInvaliditetom]
	, [ZapOsobaSInvaliditetomIznos]
	, [NetoPredPorezIPrirez]
	, [NetoPredPosPorez]
	, [NetoIsplata]
	, [ZdravstvenoZaInozemstvo]
	, [UkObustave]
	, [UkNaknade]
	, [PosebniPorezPostotak]
	, [NetoIsplataNakonObustavaNaknada]
	, [MIO1Postotak]
	, [MIO2Postotak]
	, [UkIznosBezDoprinosa]
	, [DatumObracunaOd]
	, [DatumObracunaDo]
	, [DatumDospijeca]
    FROM
	[pla].[tblObracunOsoba]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([BrutoIznosZaRazdoblje] = @BrutoIznosZaRazdoblje AND @BrutoIznosZaRazdoblje is not null)
	OR ([BrutoSatnica] = @BrutoSatnica AND @BrutoSatnica is not null)
	OR ([ProsjecnaBruto6Mjeseci] = @ProsjecnaBruto6Mjeseci AND @ProsjecnaBruto6Mjeseci is not null)
	OR ([ProsjecnaNeto6Mjeseci] = @ProsjecnaNeto6Mjeseci AND @ProsjecnaNeto6Mjeseci is not null)
	OR ([IDObracun] = @IDObracun AND @IDObracun is not null)
	OR ([OsobniOdbitak] = @OsobniOdbitak AND @OsobniOdbitak is not null)
	OR ([MaksPorezneOlaksice] = @MaksPorezneOlaksice AND @MaksPorezneOlaksice is not null)
	OR ([UkBruto] = @UkBruto AND @UkBruto is not null)
	OR ([UkMIO1Iznos] = @UkMIO1Iznos AND @UkMIO1Iznos is not null)
	OR ([UkMIO1PovecaniStazIznos] = @UkMIO1PovecaniStazIznos AND @UkMIO1PovecaniStazIznos is not null)
	OR ([UkMIO2Iznos] = @UkMIO2Iznos AND @UkMIO2Iznos is not null)
	OR ([MIO2PovecaniStazIznos] = @MIO2PovecaniStazIznos AND @MIO2PovecaniStazIznos is not null)
	OR ([IznosPoreznihOlaksica] = @IznosPoreznihOlaksica AND @IznosPoreznihOlaksica is not null)
	OR ([PoreznaOsnovica] = @PoreznaOsnovica AND @PoreznaOsnovica is not null)
	OR ([Porez15] = @Porez15 AND @Porez15 is not null)
	OR ([Porez25] = @Porez25 AND @Porez25 is not null)
	OR ([Porez35] = @Porez35 AND @Porez35 is not null)
	OR ([Porez45] = @Porez45 AND @Porez45 is not null)
	OR ([UkPorez] = @UkPorez AND @UkPorez is not null)
	OR ([Prirez] = @Prirez AND @Prirez is not null)
	OR ([PrirezIznos] = @PrirezIznos AND @PrirezIznos is not null)
	OR ([IDMjestoPrirez] = @IDMjestoPrirez AND @IDMjestoPrirez is not null)
	OR ([Zdravstveno] = @Zdravstveno AND @Zdravstveno is not null)
	OR ([Zaposljavanje] = @Zaposljavanje AND @Zaposljavanje is not null)
	OR ([Nezgoda] = @Nezgoda AND @Nezgoda is not null)
	OR ([PosPorez] = @PosPorez AND @PosPorez is not null)
	OR ([ZapOsobaSInvaliditetom] = @ZapOsobaSInvaliditetom AND @ZapOsobaSInvaliditetom is not null)
	OR ([ZapOsobaSInvaliditetomIznos] = @ZapOsobaSInvaliditetomIznos AND @ZapOsobaSInvaliditetomIznos is not null)
	OR ([NetoPredPorezIPrirez] = @NetoPredPorezIPrirez AND @NetoPredPorezIPrirez is not null)
	OR ([NetoPredPosPorez] = @NetoPredPosPorez AND @NetoPredPosPorez is not null)
	OR ([NetoIsplata] = @NetoIsplata AND @NetoIsplata is not null)
	OR ([ZdravstvenoZaInozemstvo] = @ZdravstvenoZaInozemstvo AND @ZdravstvenoZaInozemstvo is not null)
	OR ([UkObustave] = @UkObustave AND @UkObustave is not null)
	OR ([UkNaknade] = @UkNaknade AND @UkNaknade is not null)
	OR ([PosebniPorezPostotak] = @PosebniPorezPostotak AND @PosebniPorezPostotak is not null)
	OR ([NetoIsplataNakonObustavaNaknada] = @NetoIsplataNakonObustavaNaknada AND @NetoIsplataNakonObustavaNaknada is not null)
	OR ([MIO1Postotak] = @MIO1Postotak AND @MIO1Postotak is not null)
	OR ([MIO2Postotak] = @MIO2Postotak AND @MIO2Postotak is not null)
	OR ([UkIznosBezDoprinosa] = @UkIznosBezDoprinosa AND @UkIznosBezDoprinosa is not null)
	OR ([DatumObracunaOd] = @DatumObracunaOd AND @DatumObracunaOd is not null)
	OR ([DatumObracunaDo] = @DatumObracunaDo AND @DatumObracunaDo is not null)
	OR ([DatumDospijeca] = @DatumDospijeca AND @DatumDospijeca is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataProknjizen_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataProknjizen_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataProknjizen_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracunKamataProknjizen table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataProknjizen_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKnjizenjeStavka],
					[IDOrganizacija],
					[IDObracunKamata],
					[KontoSifraPrijenos],
					[DugIliPot],
					[Kontrola]
				FROM
					[fin].[tblObracunKamataProknjizen]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataProknjizen_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataProknjizen_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataProknjizen_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracunKamataProknjizen table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataProknjizen_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDKnjizenjeStavka]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDKnjizenjeStavka]'
				SET @SQL = @SQL + ', [IDOrganizacija]'
				SET @SQL = @SQL + ', [IDObracunKamata]'
				SET @SQL = @SQL + ', [KontoSifraPrijenos]'
				SET @SQL = @SQL + ', [DugIliPot]'
				SET @SQL = @SQL + ', [Kontrola]'
				SET @SQL = @SQL + ' FROM [fin].[tblObracunKamataProknjizen]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDKnjizenjeStavka],'
				SET @SQL = @SQL + ' [IDOrganizacija],'
				SET @SQL = @SQL + ' [IDObracunKamata],'
				SET @SQL = @SQL + ' [KontoSifraPrijenos],'
				SET @SQL = @SQL + ' [DugIliPot],'
				SET @SQL = @SQL + ' [Kontrola]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblObracunKamataProknjizen]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataProknjizen_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataProknjizen_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataProknjizen_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracunKamataProknjizen table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataProknjizen_Insert
(

	@IDKnjizenjeStavka int   ,

	@IDOrganizacija int   ,

	@IDObracunKamata int   ,

	@KontoSifraPrijenos varchar (9)  ,

	@DugIliPot bit   ,

	@Kontrola nvarchar (31)   OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblObracunKamataProknjizen]
					(
					[IDKnjizenjeStavka]
					,[IDOrganizacija]
					,[IDObracunKamata]
					,[KontoSifraPrijenos]
					,[DugIliPot]
					)
				VALUES
					(
					@IDKnjizenjeStavka
					,@IDOrganizacija
					,@IDObracunKamata
					,@KontoSifraPrijenos
					,@DugIliPot
					)
				
									
				-- Select computed columns into output parameters
				SELECT
 @Kontrola = [Kontrola]
				FROM
					[fin].[tblObracunKamataProknjizen]
				WHERE
[IDKnjizenjeStavka] = @IDKnjizenjeStavka 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataProknjizen_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataProknjizen_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataProknjizen_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracunKamataProknjizen table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataProknjizen_Update
(

	@IDKnjizenjeStavka int   ,

	@OriginalIDKnjizenjeStavka int   ,

	@IDOrganizacija int   ,

	@IDObracunKamata int   ,

	@KontoSifraPrijenos varchar (9)  ,

	@DugIliPot bit   ,

	@Kontrola nvarchar (31)   OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblObracunKamataProknjizen]
				SET
					[IDKnjizenjeStavka] = @IDKnjizenjeStavka
					,[IDOrganizacija] = @IDOrganizacija
					,[IDObracunKamata] = @IDObracunKamata
					,[KontoSifraPrijenos] = @KontoSifraPrijenos
					,[DugIliPot] = @DugIliPot
				WHERE
[IDKnjizenjeStavka] = @OriginalIDKnjizenjeStavka 
				
				
				-- Select computed columns into output parameters
				SELECT
 @Kontrola = [Kontrola]
				FROM
					[fin].[tblObracunKamataProknjizen]
				WHERE
[IDKnjizenjeStavka] = @IDKnjizenjeStavka 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataProknjizen_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataProknjizen_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataProknjizen_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracunKamataProknjizen table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataProknjizen_Delete
(

	@IDKnjizenjeStavka int   
)
AS


				DELETE FROM [fin].[tblObracunKamataProknjizen] WITH (ROWLOCK) 
				WHERE
					[IDKnjizenjeStavka] = @IDKnjizenjeStavka
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataProknjizen_GetByIDObracunKamata procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataProknjizen_GetByIDObracunKamata') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataProknjizen_GetByIDObracunKamata
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamataProknjizen table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataProknjizen_GetByIDObracunKamata
(

	@IDObracunKamata int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKnjizenjeStavka],
					[IDOrganizacija],
					[IDObracunKamata],
					[KontoSifraPrijenos],
					[DugIliPot],
					[Kontrola]
				FROM
					[fin].[tblObracunKamataProknjizen]
				WHERE
					[IDObracunKamata] = @IDObracunKamata
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataProknjizen_GetByIDOrganizacija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataProknjizen_GetByIDOrganizacija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataProknjizen_GetByIDOrganizacija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamataProknjizen table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataProknjizen_GetByIDOrganizacija
(

	@IDOrganizacija int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKnjizenjeStavka],
					[IDOrganizacija],
					[IDObracunKamata],
					[KontoSifraPrijenos],
					[DugIliPot],
					[Kontrola]
				FROM
					[fin].[tblObracunKamataProknjizen]
				WHERE
					[IDOrganizacija] = @IDOrganizacija
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataProknjizen_GetByIDKnjizenjeStavka procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataProknjizen_GetByIDKnjizenjeStavka') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataProknjizen_GetByIDKnjizenjeStavka
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamataProknjizen table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataProknjizen_GetByIDKnjizenjeStavka
(

	@IDKnjizenjeStavka int   
)
AS


				SELECT
					[IDKnjizenjeStavka],
					[IDOrganizacija],
					[IDObracunKamata],
					[KontoSifraPrijenos],
					[DugIliPot],
					[Kontrola]
				FROM
					[fin].[tblObracunKamataProknjizen]
				WHERE
					[IDKnjizenjeStavka] = @IDKnjizenjeStavka
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataProknjizen_GetByIDObracunKamataKontoSifraPrijenosKontrola procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataProknjizen_GetByIDObracunKamataKontoSifraPrijenosKontrola') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataProknjizen_GetByIDObracunKamataKontoSifraPrijenosKontrola
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamataProknjizen table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataProknjizen_GetByIDObracunKamataKontoSifraPrijenosKontrola
(

	@IDObracunKamata int   ,

	@KontoSifraPrijenos varchar (9)  ,

	@Kontrola nvarchar (31)  
)
AS


				SELECT
					[IDKnjizenjeStavka],
					[IDOrganizacija],
					[IDObracunKamata],
					[KontoSifraPrijenos],
					[DugIliPot],
					[Kontrola]
				FROM
					[fin].[tblObracunKamataProknjizen]
				WHERE
					[IDObracunKamata] = @IDObracunKamata
					AND [KontoSifraPrijenos] = @KontoSifraPrijenos
					AND [Kontrola] = @Kontrola
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataProknjizen_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataProknjizen_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataProknjizen_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracunKamataProknjizen table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataProknjizen_Find
(

	@SearchUsingOR bit   = null ,

	@IDKnjizenjeStavka int   = null ,

	@IDOrganizacija int   = null ,

	@IDObracunKamata int   = null ,

	@KontoSifraPrijenos varchar (9)  = null ,

	@DugIliPot bit   = null ,

	@Kontrola nvarchar (31)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [IDKnjizenjeStavka]
	, [IDOrganizacija]
	, [IDObracunKamata]
	, [KontoSifraPrijenos]
	, [DugIliPot]
	, [Kontrola]
    FROM
	[fin].[tblObracunKamataProknjizen]
    WHERE 
	 ([IDKnjizenjeStavka] = @IDKnjizenjeStavka OR @IDKnjizenjeStavka is null)
	AND ([IDOrganizacija] = @IDOrganizacija OR @IDOrganizacija is null)
	AND ([IDObracunKamata] = @IDObracunKamata OR @IDObracunKamata is null)
	AND ([KontoSifraPrijenos] = @KontoSifraPrijenos OR @KontoSifraPrijenos is null)
	AND ([DugIliPot] = @DugIliPot OR @DugIliPot is null)
	AND ([Kontrola] = @Kontrola OR @Kontrola is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [IDKnjizenjeStavka]
	, [IDOrganizacija]
	, [IDObracunKamata]
	, [KontoSifraPrijenos]
	, [DugIliPot]
	, [Kontrola]
    FROM
	[fin].[tblObracunKamataProknjizen]
    WHERE 
	 ([IDKnjizenjeStavka] = @IDKnjizenjeStavka AND @IDKnjizenjeStavka is not null)
	OR ([IDOrganizacija] = @IDOrganizacija AND @IDOrganizacija is not null)
	OR ([IDObracunKamata] = @IDObracunKamata AND @IDObracunKamata is not null)
	OR ([KontoSifraPrijenos] = @KontoSifraPrijenos AND @KontoSifraPrijenos is not null)
	OR ([DugIliPot] = @DugIliPot AND @DugIliPot is not null)
	OR ([Kontrola] = @Kontrola AND @Kontrola is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspis_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspis_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspis_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblIspis table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspis_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDTipIspisa]
				FROM
					[fin].[tblIspis]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspis_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspis_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspis_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblIspis table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspis_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [IDTipIspisa]'
				SET @SQL = @SQL + ' FROM [fin].[tblIspis]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [IDTipIspisa]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblIspis]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspis_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspis_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspis_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblIspis table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspis_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (250)  ,

	@IDTipIspisa int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblIspis]
					(
					[Naziv]
					,[IDTipIspisa]
					)
				VALUES
					(
					@Naziv
					,@IDTipIspisa
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspis_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspis_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspis_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblIspis table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspis_Update
(

	@ID int   ,

	@Naziv nvarchar (250)  ,

	@IDTipIspisa int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblIspis]
				SET
					[Naziv] = @Naziv
					,[IDTipIspisa] = @IDTipIspisa
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspis_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspis_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspis_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblIspis table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspis_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblIspis] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspis_GetByIDTipIspisa procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspis_GetByIDTipIspisa') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspis_GetByIDTipIspisa
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblIspis table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspis_GetByIDTipIspisa
(

	@IDTipIspisa int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDTipIspisa]
				FROM
					[fin].[tblIspis]
				WHERE
					[IDTipIspisa] = @IDTipIspisa
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspis_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspis_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspis_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblIspis table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspis_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[IDTipIspisa]
				FROM
					[fin].[tblIspis]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspis_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspis_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspis_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblIspis table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspis_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (250)  = null ,

	@IDTipIspisa int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [IDTipIspisa]
    FROM
	[fin].[tblIspis]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([IDTipIspisa] = @IDTipIspisa OR @IDTipIspisa is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [IDTipIspisa]
    FROM
	[fin].[tblIspis]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([IDTipIspisa] = @IDTipIspisa AND @IDTipIspisa is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaObustavaNaknada_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaObustavaNaknada_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaObustavaNaknada_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracunOsobaObustavaNaknada table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaObustavaNaknada_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[OpisPlacanja],
					[ZiroRacun],
					[Iznos],
					[DatumIsplate],
					[Model],
					[PozivNaBroj],
					[Napomena],
					[IDObustavaNaknadaTip],
					[IDObracunOsoba],
					[IDOsobaObustavaNaknada]
				FROM
					[pla].[tblObracunOsobaObustavaNaknada]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaObustavaNaknada_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaObustavaNaknada_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaObustavaNaknada_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracunOsobaObustavaNaknada table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaObustavaNaknada_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [PrimateljNaziv]'
				SET @SQL = @SQL + ', [PrimateljSjediste]'
				SET @SQL = @SQL + ', [OpisPlacanja]'
				SET @SQL = @SQL + ', [ZiroRacun]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [DatumIsplate]'
				SET @SQL = @SQL + ', [Model]'
				SET @SQL = @SQL + ', [PozivNaBroj]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [IDObustavaNaknadaTip]'
				SET @SQL = @SQL + ', [IDObracunOsoba]'
				SET @SQL = @SQL + ', [IDOsobaObustavaNaknada]'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunOsobaObustavaNaknada]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [PrimateljNaziv],'
				SET @SQL = @SQL + ' [PrimateljSjediste],'
				SET @SQL = @SQL + ' [OpisPlacanja],'
				SET @SQL = @SQL + ' [ZiroRacun],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [DatumIsplate],'
				SET @SQL = @SQL + ' [Model],'
				SET @SQL = @SQL + ' [PozivNaBroj],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [IDObustavaNaknadaTip],'
				SET @SQL = @SQL + ' [IDObracunOsoba],'
				SET @SQL = @SQL + ' [IDOsobaObustavaNaknada]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunOsobaObustavaNaknada]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaObustavaNaknada_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaObustavaNaknada_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaObustavaNaknada_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracunOsobaObustavaNaknada table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaObustavaNaknada_Insert
(

	@ID int    OUTPUT,

	@PrimateljNaziv nvarchar (50)  ,

	@PrimateljSjediste nvarchar (50)  ,

	@OpisPlacanja nvarchar (100)  ,

	@ZiroRacun nvarchar (20)  ,

	@Iznos money   ,

	@DatumIsplate datetime   ,

	@Model nvarchar (2)  ,

	@PozivNaBroj nvarchar (23)  ,

	@Napomena nvarchar (100)  ,

	@IDObustavaNaknadaTip int   ,

	@IDObracunOsoba int   ,

	@IDOsobaObustavaNaknada int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblObracunOsobaObustavaNaknada]
					(
					[PrimateljNaziv]
					,[PrimateljSjediste]
					,[OpisPlacanja]
					,[ZiroRacun]
					,[Iznos]
					,[DatumIsplate]
					,[Model]
					,[PozivNaBroj]
					,[Napomena]
					,[IDObustavaNaknadaTip]
					,[IDObracunOsoba]
					,[IDOsobaObustavaNaknada]
					)
				VALUES
					(
					@PrimateljNaziv
					,@PrimateljSjediste
					,@OpisPlacanja
					,@ZiroRacun
					,@Iznos
					,@DatumIsplate
					,@Model
					,@PozivNaBroj
					,@Napomena
					,@IDObustavaNaknadaTip
					,@IDObracunOsoba
					,@IDOsobaObustavaNaknada
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaObustavaNaknada_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaObustavaNaknada_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaObustavaNaknada_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracunOsobaObustavaNaknada table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaObustavaNaknada_Update
(

	@ID int   ,

	@PrimateljNaziv nvarchar (50)  ,

	@PrimateljSjediste nvarchar (50)  ,

	@OpisPlacanja nvarchar (100)  ,

	@ZiroRacun nvarchar (20)  ,

	@Iznos money   ,

	@DatumIsplate datetime   ,

	@Model nvarchar (2)  ,

	@PozivNaBroj nvarchar (23)  ,

	@Napomena nvarchar (100)  ,

	@IDObustavaNaknadaTip int   ,

	@IDObracunOsoba int   ,

	@IDOsobaObustavaNaknada int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblObracunOsobaObustavaNaknada]
				SET
					[PrimateljNaziv] = @PrimateljNaziv
					,[PrimateljSjediste] = @PrimateljSjediste
					,[OpisPlacanja] = @OpisPlacanja
					,[ZiroRacun] = @ZiroRacun
					,[Iznos] = @Iznos
					,[DatumIsplate] = @DatumIsplate
					,[Model] = @Model
					,[PozivNaBroj] = @PozivNaBroj
					,[Napomena] = @Napomena
					,[IDObustavaNaknadaTip] = @IDObustavaNaknadaTip
					,[IDObracunOsoba] = @IDObracunOsoba
					,[IDOsobaObustavaNaknada] = @IDOsobaObustavaNaknada
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaObustavaNaknada_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaObustavaNaknada_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaObustavaNaknada_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracunOsobaObustavaNaknada table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaObustavaNaknada_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblObracunOsobaObustavaNaknada] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaObustavaNaknada_GetByIDObracunOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaObustavaNaknada_GetByIDObracunOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaObustavaNaknada_GetByIDObracunOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsobaObustavaNaknada table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaObustavaNaknada_GetByIDObracunOsoba
(

	@IDObracunOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[OpisPlacanja],
					[ZiroRacun],
					[Iznos],
					[DatumIsplate],
					[Model],
					[PozivNaBroj],
					[Napomena],
					[IDObustavaNaknadaTip],
					[IDObracunOsoba],
					[IDOsobaObustavaNaknada]
				FROM
					[pla].[tblObracunOsobaObustavaNaknada]
				WHERE
					[IDObracunOsoba] = @IDObracunOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaObustavaNaknada_GetByIDObustavaNaknadaTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaObustavaNaknada_GetByIDObustavaNaknadaTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaObustavaNaknada_GetByIDObustavaNaknadaTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsobaObustavaNaknada table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaObustavaNaknada_GetByIDObustavaNaknadaTip
(

	@IDObustavaNaknadaTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[OpisPlacanja],
					[ZiroRacun],
					[Iznos],
					[DatumIsplate],
					[Model],
					[PozivNaBroj],
					[Napomena],
					[IDObustavaNaknadaTip],
					[IDObracunOsoba],
					[IDOsobaObustavaNaknada]
				FROM
					[pla].[tblObracunOsobaObustavaNaknada]
				WHERE
					[IDObustavaNaknadaTip] = @IDObustavaNaknadaTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaObustavaNaknada_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaObustavaNaknada_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaObustavaNaknada_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsobaObustavaNaknada table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaObustavaNaknada_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[OpisPlacanja],
					[ZiroRacun],
					[Iznos],
					[DatumIsplate],
					[Model],
					[PozivNaBroj],
					[Napomena],
					[IDObustavaNaknadaTip],
					[IDObracunOsoba],
					[IDOsobaObustavaNaknada]
				FROM
					[pla].[tblObracunOsobaObustavaNaknada]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaObustavaNaknada_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaObustavaNaknada_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaObustavaNaknada_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracunOsobaObustavaNaknada table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaObustavaNaknada_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@PrimateljNaziv nvarchar (50)  = null ,

	@PrimateljSjediste nvarchar (50)  = null ,

	@OpisPlacanja nvarchar (100)  = null ,

	@ZiroRacun nvarchar (20)  = null ,

	@Iznos money   = null ,

	@DatumIsplate datetime   = null ,

	@Model nvarchar (2)  = null ,

	@PozivNaBroj nvarchar (23)  = null ,

	@Napomena nvarchar (100)  = null ,

	@IDObustavaNaknadaTip int   = null ,

	@IDObracunOsoba int   = null ,

	@IDOsobaObustavaNaknada int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [PrimateljNaziv]
	, [PrimateljSjediste]
	, [OpisPlacanja]
	, [ZiroRacun]
	, [Iznos]
	, [DatumIsplate]
	, [Model]
	, [PozivNaBroj]
	, [Napomena]
	, [IDObustavaNaknadaTip]
	, [IDObracunOsoba]
	, [IDOsobaObustavaNaknada]
    FROM
	[pla].[tblObracunOsobaObustavaNaknada]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([PrimateljNaziv] = @PrimateljNaziv OR @PrimateljNaziv is null)
	AND ([PrimateljSjediste] = @PrimateljSjediste OR @PrimateljSjediste is null)
	AND ([OpisPlacanja] = @OpisPlacanja OR @OpisPlacanja is null)
	AND ([ZiroRacun] = @ZiroRacun OR @ZiroRacun is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
	AND ([DatumIsplate] = @DatumIsplate OR @DatumIsplate is null)
	AND ([Model] = @Model OR @Model is null)
	AND ([PozivNaBroj] = @PozivNaBroj OR @PozivNaBroj is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([IDObustavaNaknadaTip] = @IDObustavaNaknadaTip OR @IDObustavaNaknadaTip is null)
	AND ([IDObracunOsoba] = @IDObracunOsoba OR @IDObracunOsoba is null)
	AND ([IDOsobaObustavaNaknada] = @IDOsobaObustavaNaknada OR @IDOsobaObustavaNaknada is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [PrimateljNaziv]
	, [PrimateljSjediste]
	, [OpisPlacanja]
	, [ZiroRacun]
	, [Iznos]
	, [DatumIsplate]
	, [Model]
	, [PozivNaBroj]
	, [Napomena]
	, [IDObustavaNaknadaTip]
	, [IDObracunOsoba]
	, [IDOsobaObustavaNaknada]
    FROM
	[pla].[tblObracunOsobaObustavaNaknada]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([PrimateljNaziv] = @PrimateljNaziv AND @PrimateljNaziv is not null)
	OR ([PrimateljSjediste] = @PrimateljSjediste AND @PrimateljSjediste is not null)
	OR ([OpisPlacanja] = @OpisPlacanja AND @OpisPlacanja is not null)
	OR ([ZiroRacun] = @ZiroRacun AND @ZiroRacun is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	OR ([DatumIsplate] = @DatumIsplate AND @DatumIsplate is not null)
	OR ([Model] = @Model AND @Model is not null)
	OR ([PozivNaBroj] = @PozivNaBroj AND @PozivNaBroj is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([IDObustavaNaknadaTip] = @IDObustavaNaknadaTip AND @IDObustavaNaknadaTip is not null)
	OR ([IDObracunOsoba] = @IDObracunOsoba AND @IDObracunOsoba is not null)
	OR ([IDOsobaObustavaNaknada] = @IDOsobaObustavaNaknada AND @IDOsobaObustavaNaknada is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataShemaKnjiz_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataShemaKnjiz_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataShemaKnjiz_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracunKamataShemaKnjiz table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataShemaKnjiz_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[KontoZaPrebacivanje],
					[DugIliPot],
					[IDVrstaFinDokumenta]
				FROM
					[fin].[tblObracunKamataShemaKnjiz]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataShemaKnjiz_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataShemaKnjiz_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataShemaKnjiz_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracunKamataShemaKnjiz table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataShemaKnjiz_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [KontoZaPrebacivanje]'
				SET @SQL = @SQL + ', [DugIliPot]'
				SET @SQL = @SQL + ', [IDVrstaFinDokumenta]'
				SET @SQL = @SQL + ' FROM [fin].[tblObracunKamataShemaKnjiz]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [KontoZaPrebacivanje],'
				SET @SQL = @SQL + ' [DugIliPot],'
				SET @SQL = @SQL + ' [IDVrstaFinDokumenta]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblObracunKamataShemaKnjiz]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataShemaKnjiz_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataShemaKnjiz_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataShemaKnjiz_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracunKamataShemaKnjiz table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataShemaKnjiz_Insert
(

	@ID int    OUTPUT,

	@KontoZaPrebacivanje varchar (9)  ,

	@DugIliPot bit   ,

	@IDVrstaFinDokumenta int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblObracunKamataShemaKnjiz]
					(
					[KontoZaPrebacivanje]
					,[DugIliPot]
					,[IDVrstaFinDokumenta]
					)
				VALUES
					(
					@KontoZaPrebacivanje
					,@DugIliPot
					,@IDVrstaFinDokumenta
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataShemaKnjiz_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataShemaKnjiz_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataShemaKnjiz_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracunKamataShemaKnjiz table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataShemaKnjiz_Update
(

	@ID int   ,

	@KontoZaPrebacivanje varchar (9)  ,

	@DugIliPot bit   ,

	@IDVrstaFinDokumenta int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblObracunKamataShemaKnjiz]
				SET
					[KontoZaPrebacivanje] = @KontoZaPrebacivanje
					,[DugIliPot] = @DugIliPot
					,[IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataShemaKnjiz_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataShemaKnjiz_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataShemaKnjiz_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracunKamataShemaKnjiz table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataShemaKnjiz_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblObracunKamataShemaKnjiz] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataShemaKnjiz_GetByIDVrstaFinDokumenta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataShemaKnjiz_GetByIDVrstaFinDokumenta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataShemaKnjiz_GetByIDVrstaFinDokumenta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamataShemaKnjiz table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataShemaKnjiz_GetByIDVrstaFinDokumenta
(

	@IDVrstaFinDokumenta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[KontoZaPrebacivanje],
					[DugIliPot],
					[IDVrstaFinDokumenta]
				FROM
					[fin].[tblObracunKamataShemaKnjiz]
				WHERE
					[IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataShemaKnjiz_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataShemaKnjiz_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataShemaKnjiz_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamataShemaKnjiz table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataShemaKnjiz_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[KontoZaPrebacivanje],
					[DugIliPot],
					[IDVrstaFinDokumenta]
				FROM
					[fin].[tblObracunKamataShemaKnjiz]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataShemaKnjiz_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataShemaKnjiz_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataShemaKnjiz_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracunKamataShemaKnjiz table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataShemaKnjiz_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@KontoZaPrebacivanje varchar (9)  = null ,

	@DugIliPot bit   = null ,

	@IDVrstaFinDokumenta int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [KontoZaPrebacivanje]
	, [DugIliPot]
	, [IDVrstaFinDokumenta]
    FROM
	[fin].[tblObracunKamataShemaKnjiz]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([KontoZaPrebacivanje] = @KontoZaPrebacivanje OR @KontoZaPrebacivanje is null)
	AND ([DugIliPot] = @DugIliPot OR @DugIliPot is null)
	AND ([IDVrstaFinDokumenta] = @IDVrstaFinDokumenta OR @IDVrstaFinDokumenta is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [KontoZaPrebacivanje]
	, [DugIliPot]
	, [IDVrstaFinDokumenta]
    FROM
	[fin].[tblObracunKamataShemaKnjiz]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([KontoZaPrebacivanje] = @KontoZaPrebacivanje AND @KontoZaPrebacivanje is not null)
	OR ([DugIliPot] = @DugIliPot AND @DugIliPot is not null)
	OR ([IDVrstaFinDokumenta] = @IDVrstaFinDokumenta AND @IDVrstaFinDokumenta is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspisKolona_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspisKolona_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspisKolona_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblIspisKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspisKolona_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Naziv2],
					[IDIspis]
				FROM
					[fin].[tblIspisKolona]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspisKolona_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspisKolona_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspisKolona_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblIspisKolona table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspisKolona_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Naziv2]'
				SET @SQL = @SQL + ', [IDIspis]'
				SET @SQL = @SQL + ' FROM [fin].[tblIspisKolona]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Naziv2],'
				SET @SQL = @SQL + ' [IDIspis]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblIspisKolona]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspisKolona_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspisKolona_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspisKolona_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblIspisKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspisKolona_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (250)  ,

	@Naziv2 nvarchar (50)  ,

	@IDIspis int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblIspisKolona]
					(
					[Naziv]
					,[Naziv2]
					,[IDIspis]
					)
				VALUES
					(
					@Naziv
					,@Naziv2
					,@IDIspis
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspisKolona_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspisKolona_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspisKolona_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblIspisKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspisKolona_Update
(

	@ID int   ,

	@Naziv nvarchar (250)  ,

	@Naziv2 nvarchar (50)  ,

	@IDIspis int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblIspisKolona]
				SET
					[Naziv] = @Naziv
					,[Naziv2] = @Naziv2
					,[IDIspis] = @IDIspis
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspisKolona_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspisKolona_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspisKolona_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblIspisKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspisKolona_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblIspisKolona] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspisKolona_GetByIDIspis procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspisKolona_GetByIDIspis') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspisKolona_GetByIDIspis
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblIspisKolona table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspisKolona_GetByIDIspis
(

	@IDIspis int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Naziv2],
					[IDIspis]
				FROM
					[fin].[tblIspisKolona]
				WHERE
					[IDIspis] = @IDIspis
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspisKolona_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspisKolona_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspisKolona_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblIspisKolona table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspisKolona_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[Naziv2],
					[IDIspis]
				FROM
					[fin].[tblIspisKolona]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIspisKolona_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIspisKolona_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIspisKolona_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblIspisKolona table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIspisKolona_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (250)  = null ,

	@Naziv2 nvarchar (50)  = null ,

	@IDIspis int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Naziv2]
	, [IDIspis]
    FROM
	[fin].[tblIspisKolona]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([Naziv2] = @Naziv2 OR @Naziv2 is null)
	AND ([IDIspis] = @IDIspis OR @IDIspis is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [Naziv2]
	, [IDIspis]
    FROM
	[fin].[tblIspisKolona]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([Naziv2] = @Naziv2 AND @Naziv2 is not null)
	OR ([IDIspis] = @IDIspis AND @IDIspis is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPoreznaOlaksica_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPoreznaOlaksica_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracunOsobaPoreznaOlaksica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsobaPoreznaOlaksica],
					[IDObracunOsoba],
					[Iznos]
				FROM
					[pla].[tblObracunOsobaPoreznaOlaksica]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPoreznaOlaksica_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPoreznaOlaksica_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracunOsobaPoreznaOlaksica table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOsobaPoreznaOlaksica]'
				SET @SQL = @SQL + ', [IDObracunOsoba]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunOsobaPoreznaOlaksica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOsobaPoreznaOlaksica],'
				SET @SQL = @SQL + ' [IDObracunOsoba],'
				SET @SQL = @SQL + ' [Iznos]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblObracunOsobaPoreznaOlaksica]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPoreznaOlaksica_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPoreznaOlaksica_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracunOsobaPoreznaOlaksica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_Insert
(

	@ID int    OUTPUT,

	@IDOsobaPoreznaOlaksica int   ,

	@IDObracunOsoba int   ,

	@Iznos money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblObracunOsobaPoreznaOlaksica]
					(
					[IDOsobaPoreznaOlaksica]
					,[IDObracunOsoba]
					,[Iznos]
					)
				VALUES
					(
					@IDOsobaPoreznaOlaksica
					,@IDObracunOsoba
					,@Iznos
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPoreznaOlaksica_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPoreznaOlaksica_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracunOsobaPoreznaOlaksica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_Update
(

	@ID int   ,

	@IDOsobaPoreznaOlaksica int   ,

	@IDObracunOsoba int   ,

	@Iznos money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblObracunOsobaPoreznaOlaksica]
				SET
					[IDOsobaPoreznaOlaksica] = @IDOsobaPoreznaOlaksica
					,[IDObracunOsoba] = @IDObracunOsoba
					,[Iznos] = @Iznos
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPoreznaOlaksica_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPoreznaOlaksica_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracunOsobaPoreznaOlaksica table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblObracunOsobaPoreznaOlaksica] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPoreznaOlaksica_GetByIDObracunOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPoreznaOlaksica_GetByIDObracunOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_GetByIDObracunOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsobaPoreznaOlaksica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_GetByIDObracunOsoba
(

	@IDObracunOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsobaPoreznaOlaksica],
					[IDObracunOsoba],
					[Iznos]
				FROM
					[pla].[tblObracunOsobaPoreznaOlaksica]
				WHERE
					[IDObracunOsoba] = @IDObracunOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPoreznaOlaksica_GetByIDOsobaPoreznaOlaksica procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPoreznaOlaksica_GetByIDOsobaPoreznaOlaksica') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_GetByIDOsobaPoreznaOlaksica
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsobaPoreznaOlaksica table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_GetByIDOsobaPoreznaOlaksica
(

	@IDOsobaPoreznaOlaksica int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsobaPoreznaOlaksica],
					[IDObracunOsoba],
					[Iznos]
				FROM
					[pla].[tblObracunOsobaPoreznaOlaksica]
				WHERE
					[IDOsobaPoreznaOlaksica] = @IDOsobaPoreznaOlaksica
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPoreznaOlaksica_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPoreznaOlaksica_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunOsobaPoreznaOlaksica table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOsobaPoreznaOlaksica],
					[IDObracunOsoba],
					[Iznos]
				FROM
					[pla].[tblObracunOsobaPoreznaOlaksica]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblObracunOsobaPoreznaOlaksica_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblObracunOsobaPoreznaOlaksica_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracunOsobaPoreznaOlaksica table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblObracunOsobaPoreznaOlaksica_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOsobaPoreznaOlaksica int   = null ,

	@IDObracunOsoba int   = null ,

	@Iznos money   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOsobaPoreznaOlaksica]
	, [IDObracunOsoba]
	, [Iznos]
    FROM
	[pla].[tblObracunOsobaPoreznaOlaksica]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOsobaPoreznaOlaksica] = @IDOsobaPoreznaOlaksica OR @IDOsobaPoreznaOlaksica is null)
	AND ([IDObracunOsoba] = @IDObracunOsoba OR @IDObracunOsoba is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOsobaPoreznaOlaksica]
	, [IDObracunOsoba]
	, [Iznos]
    FROM
	[pla].[tblObracunOsobaPoreznaOlaksica]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOsobaPoreznaOlaksica] = @IDOsobaPoreznaOlaksica AND @IDOsobaPoreznaOlaksica is not null)
	OR ([IDObracunOsoba] = @IDObracunOsoba AND @IDObracunOsoba is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataStavke_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataStavke_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataStavke_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblObracunKamataStavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataStavke_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDObracunKamata],
					[Faktura],
					[IDKnjizenje],
					[DatumFakture],
					[DatumZadnjeUplate],
					[Iznos],
					[RazdobljeOd],
					[RazdobljeDo],
					[Dana],
					[Stopa],
					[IznosKamate],
					[StopaOd],
					[StopaDo],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified]
				FROM
					[fin].[tblObracunKamataStavke]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataStavke_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataStavke_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataStavke_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblObracunKamataStavke table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataStavke_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDObracunKamata]'
				SET @SQL = @SQL + ', [Faktura]'
				SET @SQL = @SQL + ', [IDKnjizenje]'
				SET @SQL = @SQL + ', [DatumFakture]'
				SET @SQL = @SQL + ', [DatumZadnjeUplate]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [RazdobljeOd]'
				SET @SQL = @SQL + ', [RazdobljeDo]'
				SET @SQL = @SQL + ', [Dana]'
				SET @SQL = @SQL + ', [Stopa]'
				SET @SQL = @SQL + ', [IznosKamate]'
				SET @SQL = @SQL + ', [StopaOd]'
				SET @SQL = @SQL + ', [StopaDo]'
				SET @SQL = @SQL + ', [IDUserCreated]'
				SET @SQL = @SQL + ', [IDUserModified]'
				SET @SQL = @SQL + ', [DateCreated]'
				SET @SQL = @SQL + ', [DateModified]'
				SET @SQL = @SQL + ' FROM [fin].[tblObracunKamataStavke]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDObracunKamata],'
				SET @SQL = @SQL + ' [Faktura],'
				SET @SQL = @SQL + ' [IDKnjizenje],'
				SET @SQL = @SQL + ' [DatumFakture],'
				SET @SQL = @SQL + ' [DatumZadnjeUplate],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [RazdobljeOd],'
				SET @SQL = @SQL + ' [RazdobljeDo],'
				SET @SQL = @SQL + ' [Dana],'
				SET @SQL = @SQL + ' [Stopa],'
				SET @SQL = @SQL + ' [IznosKamate],'
				SET @SQL = @SQL + ' [StopaOd],'
				SET @SQL = @SQL + ' [StopaDo],'
				SET @SQL = @SQL + ' [IDUserCreated],'
				SET @SQL = @SQL + ' [IDUserModified],'
				SET @SQL = @SQL + ' [DateCreated],'
				SET @SQL = @SQL + ' [DateModified]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblObracunKamataStavke]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataStavke_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataStavke_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataStavke_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblObracunKamataStavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataStavke_Insert
(

	@ID int    OUTPUT,

	@IDObracunKamata int   ,

	@Faktura nvarchar (50)  ,

	@IDKnjizenje int   ,

	@DatumFakture datetime   ,

	@DatumZadnjeUplate datetime   ,

	@Iznos money   ,

	@RazdobljeOd datetime   ,

	@RazdobljeDo datetime   ,

	@Dana int   ,

	@Stopa float   ,

	@IznosKamate money   ,

	@StopaOd datetime   ,

	@StopaDo datetime   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@DateCreated datetime   ,

	@DateModified datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblObracunKamataStavke]
					(
					[IDObracunKamata]
					,[Faktura]
					,[IDKnjizenje]
					,[DatumFakture]
					,[DatumZadnjeUplate]
					,[Iznos]
					,[RazdobljeOd]
					,[RazdobljeDo]
					,[Dana]
					,[Stopa]
					,[IznosKamate]
					,[StopaOd]
					,[StopaDo]
					,[IDUserCreated]
					,[IDUserModified]
					,[DateCreated]
					,[DateModified]
					)
				VALUES
					(
					@IDObracunKamata
					,@Faktura
					,@IDKnjizenje
					,@DatumFakture
					,@DatumZadnjeUplate
					,@Iznos
					,@RazdobljeOd
					,@RazdobljeDo
					,@Dana
					,@Stopa
					,@IznosKamate
					,@StopaOd
					,@StopaDo
					,@IDUserCreated
					,@IDUserModified
					,@DateCreated
					,@DateModified
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataStavke_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataStavke_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataStavke_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblObracunKamataStavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataStavke_Update
(

	@ID int   ,

	@IDObracunKamata int   ,

	@Faktura nvarchar (50)  ,

	@IDKnjizenje int   ,

	@DatumFakture datetime   ,

	@DatumZadnjeUplate datetime   ,

	@Iznos money   ,

	@RazdobljeOd datetime   ,

	@RazdobljeDo datetime   ,

	@Dana int   ,

	@Stopa float   ,

	@IznosKamate money   ,

	@StopaOd datetime   ,

	@StopaDo datetime   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@DateCreated datetime   ,

	@DateModified datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblObracunKamataStavke]
				SET
					[IDObracunKamata] = @IDObracunKamata
					,[Faktura] = @Faktura
					,[IDKnjizenje] = @IDKnjizenje
					,[DatumFakture] = @DatumFakture
					,[DatumZadnjeUplate] = @DatumZadnjeUplate
					,[Iznos] = @Iznos
					,[RazdobljeOd] = @RazdobljeOd
					,[RazdobljeDo] = @RazdobljeDo
					,[Dana] = @Dana
					,[Stopa] = @Stopa
					,[IznosKamate] = @IznosKamate
					,[StopaOd] = @StopaOd
					,[StopaDo] = @StopaDo
					,[IDUserCreated] = @IDUserCreated
					,[IDUserModified] = @IDUserModified
					,[DateCreated] = @DateCreated
					,[DateModified] = @DateModified
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataStavke_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataStavke_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataStavke_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblObracunKamataStavke table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataStavke_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblObracunKamataStavke] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataStavke_GetByIDObracunKamata procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataStavke_GetByIDObracunKamata') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataStavke_GetByIDObracunKamata
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamataStavke table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataStavke_GetByIDObracunKamata
(

	@IDObracunKamata int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDObracunKamata],
					[Faktura],
					[IDKnjizenje],
					[DatumFakture],
					[DatumZadnjeUplate],
					[Iznos],
					[RazdobljeOd],
					[RazdobljeDo],
					[Dana],
					[Stopa],
					[IznosKamate],
					[StopaOd],
					[StopaDo],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified]
				FROM
					[fin].[tblObracunKamataStavke]
				WHERE
					[IDObracunKamata] = @IDObracunKamata
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataStavke_GetByIDKnjizenje procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataStavke_GetByIDKnjizenje') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataStavke_GetByIDKnjizenje
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamataStavke table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataStavke_GetByIDKnjizenje
(

	@IDKnjizenje int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDObracunKamata],
					[Faktura],
					[IDKnjizenje],
					[DatumFakture],
					[DatumZadnjeUplate],
					[Iznos],
					[RazdobljeOd],
					[RazdobljeDo],
					[Dana],
					[Stopa],
					[IznosKamate],
					[StopaOd],
					[StopaDo],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified]
				FROM
					[fin].[tblObracunKamataStavke]
				WHERE
					[IDKnjizenje] = @IDKnjizenje
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataStavke_GetByFaktura procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataStavke_GetByFaktura') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataStavke_GetByFaktura
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamataStavke table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataStavke_GetByFaktura
(

	@Faktura nvarchar (50)  
)
AS


				SELECT
					[ID],
					[IDObracunKamata],
					[Faktura],
					[IDKnjizenje],
					[DatumFakture],
					[DatumZadnjeUplate],
					[Iznos],
					[RazdobljeOd],
					[RazdobljeDo],
					[Dana],
					[Stopa],
					[IznosKamate],
					[StopaOd],
					[StopaDo],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified]
				FROM
					[fin].[tblObracunKamataStavke]
				WHERE
					[Faktura] = @Faktura
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataStavke_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataStavke_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataStavke_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblObracunKamataStavke table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataStavke_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDObracunKamata],
					[Faktura],
					[IDKnjizenje],
					[DatumFakture],
					[DatumZadnjeUplate],
					[Iznos],
					[RazdobljeOd],
					[RazdobljeDo],
					[Dana],
					[Stopa],
					[IznosKamate],
					[StopaOd],
					[StopaDo],
					[IDUserCreated],
					[IDUserModified],
					[DateCreated],
					[DateModified]
				FROM
					[fin].[tblObracunKamataStavke]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblObracunKamataStavke_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblObracunKamataStavke_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblObracunKamataStavke_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblObracunKamataStavke table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblObracunKamataStavke_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDObracunKamata int   = null ,

	@Faktura nvarchar (50)  = null ,

	@IDKnjizenje int   = null ,

	@DatumFakture datetime   = null ,

	@DatumZadnjeUplate datetime   = null ,

	@Iznos money   = null ,

	@RazdobljeOd datetime   = null ,

	@RazdobljeDo datetime   = null ,

	@Dana int   = null ,

	@Stopa float   = null ,

	@IznosKamate money   = null ,

	@StopaOd datetime   = null ,

	@StopaDo datetime   = null ,

	@IDUserCreated int   = null ,

	@IDUserModified int   = null ,

	@DateCreated datetime   = null ,

	@DateModified datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDObracunKamata]
	, [Faktura]
	, [IDKnjizenje]
	, [DatumFakture]
	, [DatumZadnjeUplate]
	, [Iznos]
	, [RazdobljeOd]
	, [RazdobljeDo]
	, [Dana]
	, [Stopa]
	, [IznosKamate]
	, [StopaOd]
	, [StopaDo]
	, [IDUserCreated]
	, [IDUserModified]
	, [DateCreated]
	, [DateModified]
    FROM
	[fin].[tblObracunKamataStavke]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDObracunKamata] = @IDObracunKamata OR @IDObracunKamata is null)
	AND ([Faktura] = @Faktura OR @Faktura is null)
	AND ([IDKnjizenje] = @IDKnjizenje OR @IDKnjizenje is null)
	AND ([DatumFakture] = @DatumFakture OR @DatumFakture is null)
	AND ([DatumZadnjeUplate] = @DatumZadnjeUplate OR @DatumZadnjeUplate is null)
	AND ([Iznos] = @Iznos OR @Iznos is null)
	AND ([RazdobljeOd] = @RazdobljeOd OR @RazdobljeOd is null)
	AND ([RazdobljeDo] = @RazdobljeDo OR @RazdobljeDo is null)
	AND ([Dana] = @Dana OR @Dana is null)
	AND ([Stopa] = @Stopa OR @Stopa is null)
	AND ([IznosKamate] = @IznosKamate OR @IznosKamate is null)
	AND ([StopaOd] = @StopaOd OR @StopaOd is null)
	AND ([StopaDo] = @StopaDo OR @StopaDo is null)
	AND ([IDUserCreated] = @IDUserCreated OR @IDUserCreated is null)
	AND ([IDUserModified] = @IDUserModified OR @IDUserModified is null)
	AND ([DateCreated] = @DateCreated OR @DateCreated is null)
	AND ([DateModified] = @DateModified OR @DateModified is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDObracunKamata]
	, [Faktura]
	, [IDKnjizenje]
	, [DatumFakture]
	, [DatumZadnjeUplate]
	, [Iznos]
	, [RazdobljeOd]
	, [RazdobljeDo]
	, [Dana]
	, [Stopa]
	, [IznosKamate]
	, [StopaOd]
	, [StopaDo]
	, [IDUserCreated]
	, [IDUserModified]
	, [DateCreated]
	, [DateModified]
    FROM
	[fin].[tblObracunKamataStavke]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDObracunKamata] = @IDObracunKamata AND @IDObracunKamata is not null)
	OR ([Faktura] = @Faktura AND @Faktura is not null)
	OR ([IDKnjizenje] = @IDKnjizenje AND @IDKnjizenje is not null)
	OR ([DatumFakture] = @DatumFakture AND @DatumFakture is not null)
	OR ([DatumZadnjeUplate] = @DatumZadnjeUplate AND @DatumZadnjeUplate is not null)
	OR ([Iznos] = @Iznos AND @Iznos is not null)
	OR ([RazdobljeOd] = @RazdobljeOd AND @RazdobljeOd is not null)
	OR ([RazdobljeDo] = @RazdobljeDo AND @RazdobljeDo is not null)
	OR ([Dana] = @Dana AND @Dana is not null)
	OR ([Stopa] = @Stopa AND @Stopa is not null)
	OR ([IznosKamate] = @IznosKamate AND @IznosKamate is not null)
	OR ([StopaOd] = @StopaOd AND @StopaOd is not null)
	OR ([StopaDo] = @StopaDo AND @StopaDo is not null)
	OR ([IDUserCreated] = @IDUserCreated AND @IDUserCreated is not null)
	OR ([IDUserModified] = @IDUserModified AND @IDUserModified is not null)
	OR ([DateCreated] = @DateCreated AND @DateCreated is not null)
	OR ([DateModified] = @DateModified AND @DateModified is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDozvole_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDozvole_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDozvole_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblGrupaDozvole table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDozvole_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDGrupaDjelatnik],
					[OrgJed],
					[DozvolaZapisa],
					[DozvolaPregled],
					[ID]
				FROM
					[dbo].[tblGrupaDozvole]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDozvole_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDozvole_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDozvole_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblGrupaDozvole table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDozvole_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDGrupaDjelatnik]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDGrupaDjelatnik]'
				SET @SQL = @SQL + ', [OrgJed]'
				SET @SQL = @SQL + ', [DozvolaZapisa]'
				SET @SQL = @SQL + ', [DozvolaPregled]'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ' FROM [dbo].[tblGrupaDozvole]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDGrupaDjelatnik],'
				SET @SQL = @SQL + ' [OrgJed],'
				SET @SQL = @SQL + ' [DozvolaZapisa],'
				SET @SQL = @SQL + ' [DozvolaPregled],'
				SET @SQL = @SQL + ' [ID]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblGrupaDozvole]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDozvole_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDozvole_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDozvole_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblGrupaDozvole table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDozvole_Insert
(

	@IDGrupaDjelatnik int   ,

	@OrgJed nvarchar (200)  ,

	@DozvolaZapisa int   ,

	@DozvolaPregled int   ,

	@ID int    OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblGrupaDozvole]
					(
					[IDGrupaDjelatnik]
					,[OrgJed]
					,[DozvolaZapisa]
					,[DozvolaPregled]
					)
				VALUES
					(
					@IDGrupaDjelatnik
					,@OrgJed
					,@DozvolaZapisa
					,@DozvolaPregled
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDozvole_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDozvole_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDozvole_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblGrupaDozvole table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDozvole_Update
(

	@IDGrupaDjelatnik int   ,

	@OrgJed nvarchar (200)  ,

	@DozvolaZapisa int   ,

	@DozvolaPregled int   ,

	@ID int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblGrupaDozvole]
				SET
					[IDGrupaDjelatnik] = @IDGrupaDjelatnik
					,[OrgJed] = @OrgJed
					,[DozvolaZapisa] = @DozvolaZapisa
					,[DozvolaPregled] = @DozvolaPregled
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDozvole_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDozvole_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDozvole_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblGrupaDozvole table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDozvole_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblGrupaDozvole] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDozvole_GetByIDGrupaDjelatnik procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDozvole_GetByIDGrupaDjelatnik') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDozvole_GetByIDGrupaDjelatnik
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDozvole table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDozvole_GetByIDGrupaDjelatnik
(

	@IDGrupaDjelatnik int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDGrupaDjelatnik],
					[OrgJed],
					[DozvolaZapisa],
					[DozvolaPregled],
					[ID]
				FROM
					[dbo].[tblGrupaDozvole]
				WHERE
					[IDGrupaDjelatnik] = @IDGrupaDjelatnik
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDozvole_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDozvole_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDozvole_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDozvole table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDozvole_GetByID
(

	@ID int   
)
AS


				SELECT
					[IDGrupaDjelatnik],
					[OrgJed],
					[DozvolaZapisa],
					[DozvolaPregled],
					[ID]
				FROM
					[dbo].[tblGrupaDozvole]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDozvole_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDozvole_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDozvole_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblGrupaDozvole table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDozvole_Find
(

	@SearchUsingOR bit   = null ,

	@IDGrupaDjelatnik int   = null ,

	@OrgJed nvarchar (200)  = null ,

	@DozvolaZapisa int   = null ,

	@DozvolaPregled int   = null ,

	@ID int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [IDGrupaDjelatnik]
	, [OrgJed]
	, [DozvolaZapisa]
	, [DozvolaPregled]
	, [ID]
    FROM
	[dbo].[tblGrupaDozvole]
    WHERE 
	 ([IDGrupaDjelatnik] = @IDGrupaDjelatnik OR @IDGrupaDjelatnik is null)
	AND ([OrgJed] = @OrgJed OR @OrgJed is null)
	AND ([DozvolaZapisa] = @DozvolaZapisa OR @DozvolaZapisa is null)
	AND ([DozvolaPregled] = @DozvolaPregled OR @DozvolaPregled is null)
	AND ([ID] = @ID OR @ID is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [IDGrupaDjelatnik]
	, [OrgJed]
	, [DozvolaZapisa]
	, [DozvolaPregled]
	, [ID]
    FROM
	[dbo].[tblGrupaDozvole]
    WHERE 
	 ([IDGrupaDjelatnik] = @IDGrupaDjelatnik AND @IDGrupaDjelatnik is not null)
	OR ([OrgJed] = @OrgJed AND @OrgJed is not null)
	OR ([DozvolaZapisa] = @DozvolaZapisa AND @DozvolaZapisa is not null)
	OR ([DozvolaPregled] = @DozvolaPregled AND @DozvolaPregled is not null)
	OR ([ID] = @ID AND @ID is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikReport_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikReport_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikReport_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblGrupaDjelatnikReport table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikReport_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDGrupaDijelatnik],
					[IDReport]
				FROM
					[dbo].[tblGrupaDjelatnikReport]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikReport_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikReport_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikReport_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblGrupaDjelatnikReport table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikReport_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDGrupaDijelatnik]'
				SET @SQL = @SQL + ', [IDReport]'
				SET @SQL = @SQL + ' FROM [dbo].[tblGrupaDjelatnikReport]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDGrupaDijelatnik],'
				SET @SQL = @SQL + ' [IDReport]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblGrupaDjelatnikReport]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikReport_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikReport_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikReport_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblGrupaDjelatnikReport table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikReport_Insert
(

	@ID int    OUTPUT,

	@IDGrupaDijelatnik int   ,

	@IDReport int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblGrupaDjelatnikReport]
					(
					[IDGrupaDijelatnik]
					,[IDReport]
					)
				VALUES
					(
					@IDGrupaDijelatnik
					,@IDReport
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikReport_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikReport_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikReport_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblGrupaDjelatnikReport table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikReport_Update
(

	@ID int   ,

	@IDGrupaDijelatnik int   ,

	@IDReport int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblGrupaDjelatnikReport]
				SET
					[IDGrupaDijelatnik] = @IDGrupaDijelatnik
					,[IDReport] = @IDReport
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikReport_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikReport_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikReport_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblGrupaDjelatnikReport table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikReport_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblGrupaDjelatnikReport] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikReport_GetByIDGrupaDijelatnik procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikReport_GetByIDGrupaDijelatnik') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikReport_GetByIDGrupaDijelatnik
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDjelatnikReport table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikReport_GetByIDGrupaDijelatnik
(

	@IDGrupaDijelatnik int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDGrupaDijelatnik],
					[IDReport]
				FROM
					[dbo].[tblGrupaDjelatnikReport]
				WHERE
					[IDGrupaDijelatnik] = @IDGrupaDijelatnik
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikReport_GetByIDReport procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikReport_GetByIDReport') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikReport_GetByIDReport
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDjelatnikReport table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikReport_GetByIDReport
(

	@IDReport int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDGrupaDijelatnik],
					[IDReport]
				FROM
					[dbo].[tblGrupaDjelatnikReport]
				WHERE
					[IDReport] = @IDReport
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikReport_GetByIDGrupaDijelatnikIDReport procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikReport_GetByIDGrupaDijelatnikIDReport') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikReport_GetByIDGrupaDijelatnikIDReport
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDjelatnikReport table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikReport_GetByIDGrupaDijelatnikIDReport
(

	@IDGrupaDijelatnik int   ,

	@IDReport int   
)
AS


				SELECT
					[ID],
					[IDGrupaDijelatnik],
					[IDReport]
				FROM
					[dbo].[tblGrupaDjelatnikReport]
				WHERE
					[IDGrupaDijelatnik] = @IDGrupaDijelatnik
					AND [IDReport] = @IDReport
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikReport_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikReport_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikReport_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblGrupaDjelatnikReport table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikReport_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDGrupaDijelatnik],
					[IDReport]
				FROM
					[dbo].[tblGrupaDjelatnikReport]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblGrupaDjelatnikReport_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblGrupaDjelatnikReport_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblGrupaDjelatnikReport_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblGrupaDjelatnikReport table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblGrupaDjelatnikReport_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDGrupaDijelatnik int   = null ,

	@IDReport int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDGrupaDijelatnik]
	, [IDReport]
    FROM
	[dbo].[tblGrupaDjelatnikReport]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDGrupaDijelatnik] = @IDGrupaDijelatnik OR @IDGrupaDijelatnik is null)
	AND ([IDReport] = @IDReport OR @IDReport is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDGrupaDijelatnik]
	, [IDReport]
    FROM
	[dbo].[tblGrupaDjelatnikReport]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDGrupaDijelatnik] = @IDGrupaDijelatnik AND @IDGrupaDijelatnik is not null)
	OR ([IDReport] = @IDReport AND @IDReport is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjesto_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjesto_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjesto_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjesto_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[PostanskiBroj],
					[SifraOpcine],
					[Prirez],
					[ZiroRacunZaPorezPrirez],
					[TipMjesta],
					[IDNadMjesto],
					[Hierarchy],
					[Lvl],
					[SifraOpcineRegos]
				FROM
					[dbo].[tblMjesto]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjesto_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjesto_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjesto_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblMjesto table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjesto_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [PostanskiBroj]'
				SET @SQL = @SQL + ', [SifraOpcine]'
				SET @SQL = @SQL + ', [Prirez]'
				SET @SQL = @SQL + ', [ZiroRacunZaPorezPrirez]'
				SET @SQL = @SQL + ', [TipMjesta]'
				SET @SQL = @SQL + ', [IDNadMjesto]'
				SET @SQL = @SQL + ', [Hierarchy]'
				SET @SQL = @SQL + ', [Lvl]'
				SET @SQL = @SQL + ', [SifraOpcineRegos]'
				SET @SQL = @SQL + ' FROM [dbo].[tblMjesto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [PostanskiBroj],'
				SET @SQL = @SQL + ' [SifraOpcine],'
				SET @SQL = @SQL + ' [Prirez],'
				SET @SQL = @SQL + ' [ZiroRacunZaPorezPrirez],'
				SET @SQL = @SQL + ' [TipMjesta],'
				SET @SQL = @SQL + ' [IDNadMjesto],'
				SET @SQL = @SQL + ' [Hierarchy],'
				SET @SQL = @SQL + ' [Lvl],'
				SET @SQL = @SQL + ' [SifraOpcineRegos]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblMjesto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjesto_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjesto_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjesto_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjesto_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (200)  ,

	@PostanskiBroj int   ,

	@SifraOpcine int   ,

	@Prirez real   ,

	@ZiroRacunZaPorezPrirez nvarchar (50)  ,

	@TipMjesta int   ,

	@IDNadMjesto int   ,

	@Hierarchy nvarchar (200)  ,

	@Lvl int   ,

	@SifraOpcineRegos nvarchar (5)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblMjesto]
					(
					[Naziv]
					,[PostanskiBroj]
					,[SifraOpcine]
					,[Prirez]
					,[ZiroRacunZaPorezPrirez]
					,[TipMjesta]
					,[IDNadMjesto]
					,[Hierarchy]
					,[Lvl]
					,[SifraOpcineRegos]
					)
				VALUES
					(
					@Naziv
					,@PostanskiBroj
					,@SifraOpcine
					,@Prirez
					,@ZiroRacunZaPorezPrirez
					,@TipMjesta
					,@IDNadMjesto
					,@Hierarchy
					,@Lvl
					,@SifraOpcineRegos
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjesto_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjesto_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjesto_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjesto_Update
(

	@ID int   ,

	@Naziv nvarchar (200)  ,

	@PostanskiBroj int   ,

	@SifraOpcine int   ,

	@Prirez real   ,

	@ZiroRacunZaPorezPrirez nvarchar (50)  ,

	@TipMjesta int   ,

	@IDNadMjesto int   ,

	@Hierarchy nvarchar (200)  ,

	@Lvl int   ,

	@SifraOpcineRegos nvarchar (5)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblMjesto]
				SET
					[Naziv] = @Naziv
					,[PostanskiBroj] = @PostanskiBroj
					,[SifraOpcine] = @SifraOpcine
					,[Prirez] = @Prirez
					,[ZiroRacunZaPorezPrirez] = @ZiroRacunZaPorezPrirez
					,[TipMjesta] = @TipMjesta
					,[IDNadMjesto] = @IDNadMjesto
					,[Hierarchy] = @Hierarchy
					,[Lvl] = @Lvl
					,[SifraOpcineRegos] = @SifraOpcineRegos
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjesto_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjesto_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjesto_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblMjesto table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjesto_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblMjesto] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjesto_GetByIDNadMjesto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjesto_GetByIDNadMjesto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjesto_GetByIDNadMjesto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblMjesto table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjesto_GetByIDNadMjesto
(

	@IDNadMjesto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[PostanskiBroj],
					[SifraOpcine],
					[Prirez],
					[ZiroRacunZaPorezPrirez],
					[TipMjesta],
					[IDNadMjesto],
					[Hierarchy],
					[Lvl],
					[SifraOpcineRegos]
				FROM
					[dbo].[tblMjesto]
				WHERE
					[IDNadMjesto] = @IDNadMjesto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjesto_GetByTipMjesta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjesto_GetByTipMjesta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjesto_GetByTipMjesta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblMjesto table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjesto_GetByTipMjesta
(

	@TipMjesta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[PostanskiBroj],
					[SifraOpcine],
					[Prirez],
					[ZiroRacunZaPorezPrirez],
					[TipMjesta],
					[IDNadMjesto],
					[Hierarchy],
					[Lvl],
					[SifraOpcineRegos]
				FROM
					[dbo].[tblMjesto]
				WHERE
					[TipMjesta] = @TipMjesta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjesto_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjesto_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjesto_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblMjesto table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjesto_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv],
					[PostanskiBroj],
					[SifraOpcine],
					[Prirez],
					[ZiroRacunZaPorezPrirez],
					[TipMjesta],
					[IDNadMjesto],
					[Hierarchy],
					[Lvl],
					[SifraOpcineRegos]
				FROM
					[dbo].[tblMjesto]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblMjesto_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblMjesto_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblMjesto_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblMjesto table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblMjesto_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (200)  = null ,

	@PostanskiBroj int   = null ,

	@SifraOpcine int   = null ,

	@Prirez real   = null ,

	@ZiroRacunZaPorezPrirez nvarchar (50)  = null ,

	@TipMjesta int   = null ,

	@IDNadMjesto int   = null ,

	@Hierarchy nvarchar (200)  = null ,

	@Lvl int   = null ,

	@SifraOpcineRegos nvarchar (5)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [PostanskiBroj]
	, [SifraOpcine]
	, [Prirez]
	, [ZiroRacunZaPorezPrirez]
	, [TipMjesta]
	, [IDNadMjesto]
	, [Hierarchy]
	, [Lvl]
	, [SifraOpcineRegos]
    FROM
	[dbo].[tblMjesto]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
	AND ([PostanskiBroj] = @PostanskiBroj OR @PostanskiBroj is null)
	AND ([SifraOpcine] = @SifraOpcine OR @SifraOpcine is null)
	AND ([Prirez] = @Prirez OR @Prirez is null)
	AND ([ZiroRacunZaPorezPrirez] = @ZiroRacunZaPorezPrirez OR @ZiroRacunZaPorezPrirez is null)
	AND ([TipMjesta] = @TipMjesta OR @TipMjesta is null)
	AND ([IDNadMjesto] = @IDNadMjesto OR @IDNadMjesto is null)
	AND ([Hierarchy] = @Hierarchy OR @Hierarchy is null)
	AND ([Lvl] = @Lvl OR @Lvl is null)
	AND ([SifraOpcineRegos] = @SifraOpcineRegos OR @SifraOpcineRegos is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
	, [PostanskiBroj]
	, [SifraOpcine]
	, [Prirez]
	, [ZiroRacunZaPorezPrirez]
	, [TipMjesta]
	, [IDNadMjesto]
	, [Hierarchy]
	, [Lvl]
	, [SifraOpcineRegos]
    FROM
	[dbo].[tblMjesto]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	OR ([PostanskiBroj] = @PostanskiBroj AND @PostanskiBroj is not null)
	OR ([SifraOpcine] = @SifraOpcine AND @SifraOpcine is not null)
	OR ([Prirez] = @Prirez AND @Prirez is not null)
	OR ([ZiroRacunZaPorezPrirez] = @ZiroRacunZaPorezPrirez AND @ZiroRacunZaPorezPrirez is not null)
	OR ([TipMjesta] = @TipMjesta AND @TipMjesta is not null)
	OR ([IDNadMjesto] = @IDNadMjesto AND @IDNadMjesto is not null)
	OR ([Hierarchy] = @Hierarchy AND @Hierarchy is not null)
	OR ([Lvl] = @Lvl AND @Lvl is not null)
	OR ([SifraOpcineRegos] = @SifraOpcineRegos AND @SifraOpcineRegos is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblInvaliditet_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblInvaliditet_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblInvaliditet_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblInvaliditet table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblInvaliditet_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[Stupanj],
					[DatumOd],
					[DatumDo]
				FROM
					[pla].[tblInvaliditet]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblInvaliditet_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblInvaliditet_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblInvaliditet_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblInvaliditet table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblInvaliditet_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDOsoba]'
				SET @SQL = @SQL + ', [Stupanj]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ' FROM [pla].[tblInvaliditet]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDOsoba],'
				SET @SQL = @SQL + ' [Stupanj],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[tblInvaliditet]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblInvaliditet_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblInvaliditet_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblInvaliditet_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblInvaliditet table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblInvaliditet_Insert
(

	@ID int    OUTPUT,

	@IDOsoba int   ,

	@Stupanj nvarchar (50)  ,

	@DatumOd datetime   ,

	@DatumDo datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [pla].[tblInvaliditet]
					(
					[IDOsoba]
					,[Stupanj]
					,[DatumOd]
					,[DatumDo]
					)
				VALUES
					(
					@IDOsoba
					,@Stupanj
					,@DatumOd
					,@DatumDo
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblInvaliditet_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblInvaliditet_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblInvaliditet_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblInvaliditet table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblInvaliditet_Update
(

	@ID int   ,

	@IDOsoba int   ,

	@Stupanj nvarchar (50)  ,

	@DatumOd datetime   ,

	@DatumDo datetime   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[pla].[tblInvaliditet]
				SET
					[IDOsoba] = @IDOsoba
					,[Stupanj] = @Stupanj
					,[DatumOd] = @DatumOd
					,[DatumDo] = @DatumDo
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblInvaliditet_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblInvaliditet_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblInvaliditet_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblInvaliditet table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblInvaliditet_Delete
(

	@ID int   
)
AS


				DELETE FROM [pla].[tblInvaliditet] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblInvaliditet_GetByIDOsoba procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblInvaliditet_GetByIDOsoba') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblInvaliditet_GetByIDOsoba
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblInvaliditet table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblInvaliditet_GetByIDOsoba
(

	@IDOsoba int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDOsoba],
					[Stupanj],
					[DatumOd],
					[DatumDo]
				FROM
					[pla].[tblInvaliditet]
				WHERE
					[IDOsoba] = @IDOsoba
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblInvaliditet_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblInvaliditet_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblInvaliditet_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblInvaliditet table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblInvaliditet_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDOsoba],
					[Stupanj],
					[DatumOd],
					[DatumDo]
				FROM
					[pla].[tblInvaliditet]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.tblInvaliditet_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.tblInvaliditet_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.tblInvaliditet_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblInvaliditet table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.tblInvaliditet_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDOsoba int   = null ,

	@Stupanj nvarchar (50)  = null ,

	@DatumOd datetime   = null ,

	@DatumDo datetime   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDOsoba]
	, [Stupanj]
	, [DatumOd]
	, [DatumDo]
    FROM
	[pla].[tblInvaliditet]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDOsoba] = @IDOsoba OR @IDOsoba is null)
	AND ([Stupanj] = @Stupanj OR @Stupanj is null)
	AND ([DatumOd] = @DatumOd OR @DatumOd is null)
	AND ([DatumDo] = @DatumDo OR @DatumDo is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDOsoba]
	, [Stupanj]
	, [DatumOd]
	, [DatumDo]
    FROM
	[pla].[tblInvaliditet]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDOsoba] = @IDOsoba AND @IDOsoba is not null)
	OR ([Stupanj] = @Stupanj AND @Stupanj is not null)
	OR ([DatumOd] = @DatumOd AND @DatumOd is not null)
	OR ([DatumDo] = @DatumDo AND @DatumDo is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijent_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijent_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijent_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblKlijent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijent_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[ImeKlijenta],
					[MB],
					[Adresa],
					[IDMjesto],
					[Telefon],
					[Telefon2],
					[Fax],
					[Fax2],
					[WebAdresa],
					[ZiroRacun],
					[ZiroRacun2],
					[ZiroRacun3],
					[Napomena1],
					[Napomena2],
					[IDTip],
					[OIB],
					[GarancijaPlacanjaOpis],
					[GarancijaPlacanjaVrijednost],
					[DaniOdgodePlacanja],
					[Komentar]
				FROM
					[dbo].[tblKlijent]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijent_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijent_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijent_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblKlijent table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijent_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [ImeKlijenta]'
				SET @SQL = @SQL + ', [MB]'
				SET @SQL = @SQL + ', [Adresa]'
				SET @SQL = @SQL + ', [IDMjesto]'
				SET @SQL = @SQL + ', [Telefon]'
				SET @SQL = @SQL + ', [Telefon2]'
				SET @SQL = @SQL + ', [Fax]'
				SET @SQL = @SQL + ', [Fax2]'
				SET @SQL = @SQL + ', [WebAdresa]'
				SET @SQL = @SQL + ', [ZiroRacun]'
				SET @SQL = @SQL + ', [ZiroRacun2]'
				SET @SQL = @SQL + ', [ZiroRacun3]'
				SET @SQL = @SQL + ', [Napomena1]'
				SET @SQL = @SQL + ', [Napomena2]'
				SET @SQL = @SQL + ', [IDTip]'
				SET @SQL = @SQL + ', [OIB]'
				SET @SQL = @SQL + ', [GarancijaPlacanjaOpis]'
				SET @SQL = @SQL + ', [GarancijaPlacanjaVrijednost]'
				SET @SQL = @SQL + ', [DaniOdgodePlacanja]'
				SET @SQL = @SQL + ', [Komentar]'
				SET @SQL = @SQL + ' FROM [dbo].[tblKlijent]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [ImeKlijenta],'
				SET @SQL = @SQL + ' [MB],'
				SET @SQL = @SQL + ' [Adresa],'
				SET @SQL = @SQL + ' [IDMjesto],'
				SET @SQL = @SQL + ' [Telefon],'
				SET @SQL = @SQL + ' [Telefon2],'
				SET @SQL = @SQL + ' [Fax],'
				SET @SQL = @SQL + ' [Fax2],'
				SET @SQL = @SQL + ' [WebAdresa],'
				SET @SQL = @SQL + ' [ZiroRacun],'
				SET @SQL = @SQL + ' [ZiroRacun2],'
				SET @SQL = @SQL + ' [ZiroRacun3],'
				SET @SQL = @SQL + ' [Napomena1],'
				SET @SQL = @SQL + ' [Napomena2],'
				SET @SQL = @SQL + ' [IDTip],'
				SET @SQL = @SQL + ' [OIB],'
				SET @SQL = @SQL + ' [GarancijaPlacanjaOpis],'
				SET @SQL = @SQL + ' [GarancijaPlacanjaVrijednost],'
				SET @SQL = @SQL + ' [DaniOdgodePlacanja],'
				SET @SQL = @SQL + ' [Komentar]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblKlijent]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijent_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijent_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijent_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblKlijent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijent_Insert
(

	@ID int    OUTPUT,

	@ImeKlijenta nvarchar (200)  ,

	@MB nvarchar (15)  ,

	@Adresa nvarchar (300)  ,

	@IDMjesto int   ,

	@Telefon nvarchar (50)  ,

	@Telefon2 nvarchar (50)  ,

	@Fax nvarchar (50)  ,

	@Fax2 nvarchar (50)  ,

	@WebAdresa nvarchar (300)  ,

	@ZiroRacun nvarchar (50)  ,

	@ZiroRacun2 nvarchar (50)  ,

	@ZiroRacun3 nvarchar (50)  ,

	@Napomena1 nvarchar (250)  ,

	@Napomena2 nvarchar (250)  ,

	@IDTip int   ,

	@OIB nvarchar (50)  ,

	@GarancijaPlacanjaOpis nvarchar (100)  ,

	@GarancijaPlacanjaVrijednost money   ,

	@DaniOdgodePlacanja int   ,

	@Komentar nvarchar (80)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblKlijent]
					(
					[ImeKlijenta]
					,[MB]
					,[Adresa]
					,[IDMjesto]
					,[Telefon]
					,[Telefon2]
					,[Fax]
					,[Fax2]
					,[WebAdresa]
					,[ZiroRacun]
					,[ZiroRacun2]
					,[ZiroRacun3]
					,[Napomena1]
					,[Napomena2]
					,[IDTip]
					,[OIB]
					,[GarancijaPlacanjaOpis]
					,[GarancijaPlacanjaVrijednost]
					,[DaniOdgodePlacanja]
					,[Komentar]
					)
				VALUES
					(
					@ImeKlijenta
					,@MB
					,@Adresa
					,@IDMjesto
					,@Telefon
					,@Telefon2
					,@Fax
					,@Fax2
					,@WebAdresa
					,@ZiroRacun
					,@ZiroRacun2
					,@ZiroRacun3
					,@Napomena1
					,@Napomena2
					,@IDTip
					,@OIB
					,@GarancijaPlacanjaOpis
					,@GarancijaPlacanjaVrijednost
					,@DaniOdgodePlacanja
					,@Komentar
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijent_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijent_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijent_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblKlijent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijent_Update
(

	@ID int   ,

	@ImeKlijenta nvarchar (200)  ,

	@MB nvarchar (15)  ,

	@Adresa nvarchar (300)  ,

	@IDMjesto int   ,

	@Telefon nvarchar (50)  ,

	@Telefon2 nvarchar (50)  ,

	@Fax nvarchar (50)  ,

	@Fax2 nvarchar (50)  ,

	@WebAdresa nvarchar (300)  ,

	@ZiroRacun nvarchar (50)  ,

	@ZiroRacun2 nvarchar (50)  ,

	@ZiroRacun3 nvarchar (50)  ,

	@Napomena1 nvarchar (250)  ,

	@Napomena2 nvarchar (250)  ,

	@IDTip int   ,

	@OIB nvarchar (50)  ,

	@GarancijaPlacanjaOpis nvarchar (100)  ,

	@GarancijaPlacanjaVrijednost money   ,

	@DaniOdgodePlacanja int   ,

	@Komentar nvarchar (80)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblKlijent]
				SET
					[ImeKlijenta] = @ImeKlijenta
					,[MB] = @MB
					,[Adresa] = @Adresa
					,[IDMjesto] = @IDMjesto
					,[Telefon] = @Telefon
					,[Telefon2] = @Telefon2
					,[Fax] = @Fax
					,[Fax2] = @Fax2
					,[WebAdresa] = @WebAdresa
					,[ZiroRacun] = @ZiroRacun
					,[ZiroRacun2] = @ZiroRacun2
					,[ZiroRacun3] = @ZiroRacun3
					,[Napomena1] = @Napomena1
					,[Napomena2] = @Napomena2
					,[IDTip] = @IDTip
					,[OIB] = @OIB
					,[GarancijaPlacanjaOpis] = @GarancijaPlacanjaOpis
					,[GarancijaPlacanjaVrijednost] = @GarancijaPlacanjaVrijednost
					,[DaniOdgodePlacanja] = @DaniOdgodePlacanja
					,[Komentar] = @Komentar
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijent_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijent_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijent_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblKlijent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijent_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblKlijent] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijent_GetByIDTip procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijent_GetByIDTip') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijent_GetByIDTip
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijent table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijent_GetByIDTip
(

	@IDTip int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[ImeKlijenta],
					[MB],
					[Adresa],
					[IDMjesto],
					[Telefon],
					[Telefon2],
					[Fax],
					[Fax2],
					[WebAdresa],
					[ZiroRacun],
					[ZiroRacun2],
					[ZiroRacun3],
					[Napomena1],
					[Napomena2],
					[IDTip],
					[OIB],
					[GarancijaPlacanjaOpis],
					[GarancijaPlacanjaVrijednost],
					[DaniOdgodePlacanja],
					[Komentar]
				FROM
					[dbo].[tblKlijent]
				WHERE
					[IDTip] = @IDTip
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijent_GetByIDMjesto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijent_GetByIDMjesto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijent_GetByIDMjesto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijent table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijent_GetByIDMjesto
(

	@IDMjesto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[ImeKlijenta],
					[MB],
					[Adresa],
					[IDMjesto],
					[Telefon],
					[Telefon2],
					[Fax],
					[Fax2],
					[WebAdresa],
					[ZiroRacun],
					[ZiroRacun2],
					[ZiroRacun3],
					[Napomena1],
					[Napomena2],
					[IDTip],
					[OIB],
					[GarancijaPlacanjaOpis],
					[GarancijaPlacanjaVrijednost],
					[DaniOdgodePlacanja],
					[Komentar]
				FROM
					[dbo].[tblKlijent]
				WHERE
					[IDMjesto] = @IDMjesto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijent_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijent_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijent_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijent table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijent_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[ImeKlijenta],
					[MB],
					[Adresa],
					[IDMjesto],
					[Telefon],
					[Telefon2],
					[Fax],
					[Fax2],
					[WebAdresa],
					[ZiroRacun],
					[ZiroRacun2],
					[ZiroRacun3],
					[Napomena1],
					[Napomena2],
					[IDTip],
					[OIB],
					[GarancijaPlacanjaOpis],
					[GarancijaPlacanjaVrijednost],
					[DaniOdgodePlacanja],
					[Komentar]
				FROM
					[dbo].[tblKlijent]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijent_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijent_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijent_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblKlijent table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijent_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@ImeKlijenta nvarchar (200)  = null ,

	@MB nvarchar (15)  = null ,

	@Adresa nvarchar (300)  = null ,

	@IDMjesto int   = null ,

	@Telefon nvarchar (50)  = null ,

	@Telefon2 nvarchar (50)  = null ,

	@Fax nvarchar (50)  = null ,

	@Fax2 nvarchar (50)  = null ,

	@WebAdresa nvarchar (300)  = null ,

	@ZiroRacun nvarchar (50)  = null ,

	@ZiroRacun2 nvarchar (50)  = null ,

	@ZiroRacun3 nvarchar (50)  = null ,

	@Napomena1 nvarchar (250)  = null ,

	@Napomena2 nvarchar (250)  = null ,

	@IDTip int   = null ,

	@OIB nvarchar (50)  = null ,

	@GarancijaPlacanjaOpis nvarchar (100)  = null ,

	@GarancijaPlacanjaVrijednost money   = null ,

	@DaniOdgodePlacanja int   = null ,

	@Komentar nvarchar (80)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [ImeKlijenta]
	, [MB]
	, [Adresa]
	, [IDMjesto]
	, [Telefon]
	, [Telefon2]
	, [Fax]
	, [Fax2]
	, [WebAdresa]
	, [ZiroRacun]
	, [ZiroRacun2]
	, [ZiroRacun3]
	, [Napomena1]
	, [Napomena2]
	, [IDTip]
	, [OIB]
	, [GarancijaPlacanjaOpis]
	, [GarancijaPlacanjaVrijednost]
	, [DaniOdgodePlacanja]
	, [Komentar]
    FROM
	[dbo].[tblKlijent]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([ImeKlijenta] = @ImeKlijenta OR @ImeKlijenta is null)
	AND ([MB] = @MB OR @MB is null)
	AND ([Adresa] = @Adresa OR @Adresa is null)
	AND ([IDMjesto] = @IDMjesto OR @IDMjesto is null)
	AND ([Telefon] = @Telefon OR @Telefon is null)
	AND ([Telefon2] = @Telefon2 OR @Telefon2 is null)
	AND ([Fax] = @Fax OR @Fax is null)
	AND ([Fax2] = @Fax2 OR @Fax2 is null)
	AND ([WebAdresa] = @WebAdresa OR @WebAdresa is null)
	AND ([ZiroRacun] = @ZiroRacun OR @ZiroRacun is null)
	AND ([ZiroRacun2] = @ZiroRacun2 OR @ZiroRacun2 is null)
	AND ([ZiroRacun3] = @ZiroRacun3 OR @ZiroRacun3 is null)
	AND ([Napomena1] = @Napomena1 OR @Napomena1 is null)
	AND ([Napomena2] = @Napomena2 OR @Napomena2 is null)
	AND ([IDTip] = @IDTip OR @IDTip is null)
	AND ([OIB] = @OIB OR @OIB is null)
	AND ([GarancijaPlacanjaOpis] = @GarancijaPlacanjaOpis OR @GarancijaPlacanjaOpis is null)
	AND ([GarancijaPlacanjaVrijednost] = @GarancijaPlacanjaVrijednost OR @GarancijaPlacanjaVrijednost is null)
	AND ([DaniOdgodePlacanja] = @DaniOdgodePlacanja OR @DaniOdgodePlacanja is null)
	AND ([Komentar] = @Komentar OR @Komentar is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [ImeKlijenta]
	, [MB]
	, [Adresa]
	, [IDMjesto]
	, [Telefon]
	, [Telefon2]
	, [Fax]
	, [Fax2]
	, [WebAdresa]
	, [ZiroRacun]
	, [ZiroRacun2]
	, [ZiroRacun3]
	, [Napomena1]
	, [Napomena2]
	, [IDTip]
	, [OIB]
	, [GarancijaPlacanjaOpis]
	, [GarancijaPlacanjaVrijednost]
	, [DaniOdgodePlacanja]
	, [Komentar]
    FROM
	[dbo].[tblKlijent]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([ImeKlijenta] = @ImeKlijenta AND @ImeKlijenta is not null)
	OR ([MB] = @MB AND @MB is not null)
	OR ([Adresa] = @Adresa AND @Adresa is not null)
	OR ([IDMjesto] = @IDMjesto AND @IDMjesto is not null)
	OR ([Telefon] = @Telefon AND @Telefon is not null)
	OR ([Telefon2] = @Telefon2 AND @Telefon2 is not null)
	OR ([Fax] = @Fax AND @Fax is not null)
	OR ([Fax2] = @Fax2 AND @Fax2 is not null)
	OR ([WebAdresa] = @WebAdresa AND @WebAdresa is not null)
	OR ([ZiroRacun] = @ZiroRacun AND @ZiroRacun is not null)
	OR ([ZiroRacun2] = @ZiroRacun2 AND @ZiroRacun2 is not null)
	OR ([ZiroRacun3] = @ZiroRacun3 AND @ZiroRacun3 is not null)
	OR ([Napomena1] = @Napomena1 AND @Napomena1 is not null)
	OR ([Napomena2] = @Napomena2 AND @Napomena2 is not null)
	OR ([IDTip] = @IDTip AND @IDTip is not null)
	OR ([OIB] = @OIB AND @OIB is not null)
	OR ([GarancijaPlacanjaOpis] = @GarancijaPlacanjaOpis AND @GarancijaPlacanjaOpis is not null)
	OR ([GarancijaPlacanjaVrijednost] = @GarancijaPlacanjaVrijednost AND @GarancijaPlacanjaVrijednost is not null)
	OR ([DaniOdgodePlacanja] = @DaniOdgodePlacanja AND @DaniOdgodePlacanja is not null)
	OR ([Komentar] = @Komentar AND @Komentar is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentTip_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentTip_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentTip_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblKlijentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentTip_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblKlijentTip]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentTip_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentTip_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentTip_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblKlijentTip table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentTip_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [dbo].[tblKlijentTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblKlijentTip]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentTip_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentTip_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentTip_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblKlijentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentTip_Insert
(

	@ID int    OUTPUT,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblKlijentTip]
					(
					[Naziv]
					)
				VALUES
					(
					@Naziv
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentTip_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentTip_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentTip_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblKlijentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentTip_Update
(

	@ID int   ,

	@Naziv nvarchar (50)  
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblKlijentTip]
				SET
					[Naziv] = @Naziv
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentTip_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentTip_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentTip_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblKlijentTip table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentTip_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblKlijentTip] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentTip_GetByNaziv procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentTip_GetByNaziv') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentTip_GetByNaziv
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentTip_GetByNaziv
(

	@Naziv nvarchar (50)  
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblKlijentTip]
				WHERE
					[Naziv] = @Naziv
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentTip_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentTip_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentTip_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentTip table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentTip_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Naziv]
				FROM
					[dbo].[tblKlijentTip]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentTip_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentTip_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentTip_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblKlijentTip table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentTip_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Naziv nvarchar (50)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblKlijentTip]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Naziv] = @Naziv OR @Naziv is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Naziv]
    FROM
	[dbo].[tblKlijentTip]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Naziv] = @Naziv AND @Naziv is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblKnjizenje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Datum],
					[IDUserCreated],
					[IDUserModified],
					[IDUser],
					[DatumCreated],
					[DatumModified],
					[IDStatus]
				FROM
					[fin].[tblKnjizenje]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblKnjizenje table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [IDUserCreated]'
				SET @SQL = @SQL + ', [IDUserModified]'
				SET @SQL = @SQL + ', [IDUser]'
				SET @SQL = @SQL + ', [DatumCreated]'
				SET @SQL = @SQL + ', [DatumModified]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ' FROM [fin].[tblKnjizenje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [IDUserCreated],'
				SET @SQL = @SQL + ' [IDUserModified],'
				SET @SQL = @SQL + ' [IDUser],'
				SET @SQL = @SQL + ' [DatumCreated],'
				SET @SQL = @SQL + ' [DatumModified],'
				SET @SQL = @SQL + ' [IDStatus]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblKnjizenje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblKnjizenje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_Insert
(

	@ID int    OUTPUT,

	@Datum datetime   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@IDUser int   ,

	@DatumCreated datetime   ,

	@DatumModified datetime   ,

	@IDStatus int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblKnjizenje]
					(
					[Datum]
					,[IDUserCreated]
					,[IDUserModified]
					,[IDUser]
					,[DatumCreated]
					,[DatumModified]
					,[IDStatus]
					)
				VALUES
					(
					@Datum
					,@IDUserCreated
					,@IDUserModified
					,@IDUser
					,@DatumCreated
					,@DatumModified
					,@IDStatus
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblKnjizenje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_Update
(

	@ID int   ,

	@Datum datetime   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@IDUser int   ,

	@DatumCreated datetime   ,

	@DatumModified datetime   ,

	@IDStatus int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblKnjizenje]
				SET
					[Datum] = @Datum
					,[IDUserCreated] = @IDUserCreated
					,[IDUserModified] = @IDUserModified
					,[IDUser] = @IDUser
					,[DatumCreated] = @DatumCreated
					,[DatumModified] = @DatumModified
					,[IDStatus] = @IDStatus
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblKnjizenje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblKnjizenje] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_GetByIDUserCreated procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_GetByIDUserCreated') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_GetByIDUserCreated
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenje table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_GetByIDUserCreated
(

	@IDUserCreated int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Datum],
					[IDUserCreated],
					[IDUserModified],
					[IDUser],
					[DatumCreated],
					[DatumModified],
					[IDStatus]
				FROM
					[fin].[tblKnjizenje]
				WHERE
					[IDUserCreated] = @IDUserCreated
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_GetByIDUserModified procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_GetByIDUserModified') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_GetByIDUserModified
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenje table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_GetByIDUserModified
(

	@IDUserModified int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Datum],
					[IDUserCreated],
					[IDUserModified],
					[IDUser],
					[DatumCreated],
					[DatumModified],
					[IDStatus]
				FROM
					[fin].[tblKnjizenje]
				WHERE
					[IDUserModified] = @IDUserModified
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_GetByIDUser procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_GetByIDUser') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_GetByIDUser
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenje table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_GetByIDUser
(

	@IDUser int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Datum],
					[IDUserCreated],
					[IDUserModified],
					[IDUser],
					[DatumCreated],
					[DatumModified],
					[IDStatus]
				FROM
					[fin].[tblKnjizenje]
				WHERE
					[IDUser] = @IDUser
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_GetByIDStatus procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_GetByIDStatus') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_GetByIDStatus
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_GetByIDStatus
(

	@IDStatus int   
)
AS


				SELECT
					[ID],
					[Datum],
					[IDUserCreated],
					[IDUserModified],
					[IDUser],
					[DatumCreated],
					[DatumModified],
					[IDStatus]
				FROM
					[fin].[tblKnjizenje]
				WHERE
					[IDStatus] = @IDStatus
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Datum],
					[IDUserCreated],
					[IDUserModified],
					[IDUser],
					[DatumCreated],
					[DatumModified],
					[IDStatus]
				FROM
					[fin].[tblKnjizenje]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenje_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenje_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenje_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblKnjizenje table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenje_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Datum datetime   = null ,

	@IDUserCreated int   = null ,

	@IDUserModified int   = null ,

	@IDUser int   = null ,

	@DatumCreated datetime   = null ,

	@DatumModified datetime   = null ,

	@IDStatus int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Datum]
	, [IDUserCreated]
	, [IDUserModified]
	, [IDUser]
	, [DatumCreated]
	, [DatumModified]
	, [IDStatus]
    FROM
	[fin].[tblKnjizenje]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Datum] = @Datum OR @Datum is null)
	AND ([IDUserCreated] = @IDUserCreated OR @IDUserCreated is null)
	AND ([IDUserModified] = @IDUserModified OR @IDUserModified is null)
	AND ([IDUser] = @IDUser OR @IDUser is null)
	AND ([DatumCreated] = @DatumCreated OR @DatumCreated is null)
	AND ([DatumModified] = @DatumModified OR @DatumModified is null)
	AND ([IDStatus] = @IDStatus OR @IDStatus is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Datum]
	, [IDUserCreated]
	, [IDUserModified]
	, [IDUser]
	, [DatumCreated]
	, [DatumModified]
	, [IDStatus]
    FROM
	[fin].[tblKnjizenje]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Datum] = @Datum AND @Datum is not null)
	OR ([IDUserCreated] = @IDUserCreated AND @IDUserCreated is not null)
	OR ([IDUserModified] = @IDUserModified AND @IDUserModified is not null)
	OR ([IDUser] = @IDUser AND @IDUser is not null)
	OR ([DatumCreated] = @DatumCreated AND @DatumCreated is not null)
	OR ([DatumModified] = @DatumModified AND @DatumModified is not null)
	OR ([IDStatus] = @IDStatus AND @IDStatus is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblKnjizenjeStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblKnjizenjeStavka table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDKonto]'
				SET @SQL = @SQL + ', [IDOrganizacija]'
				SET @SQL = @SQL + ', [IDVrstaFinDokumenta]'
				SET @SQL = @SQL + ', [DatumDokumentaOriginal]'
				SET @SQL = @SQL + ', [DatumDokumentaPromjenjen]'
				SET @SQL = @SQL + ', [Nalog]'
				SET @SQL = @SQL + ', [OpisKnjizenja]'
				SET @SQL = @SQL + ', [Dug]'
				SET @SQL = @SQL + ', [Pot]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [SifraOriginalnogDokumenta]'
				SET @SQL = @SQL + ', [DatumDospijeca]'
				SET @SQL = @SQL + ', [PlacanjeModel]'
				SET @SQL = @SQL + ', [PlacanjePoziv]'
				SET @SQL = @SQL + ', [IDKnjizenja]'
				SET @SQL = @SQL + ', [DatumCreated]'
				SET @SQL = @SQL + ', [DatumModified]'
				SET @SQL = @SQL + ', [IDUserCreated]'
				SET @SQL = @SQL + ', [IDUserModified]'
				SET @SQL = @SQL + ', [PrikazUKnjizi]'
				SET @SQL = @SQL + ', [DateUICreated]'
				SET @SQL = @SQL + ', [KontoSifraPrijenos]'
				SET @SQL = @SQL + ', [IDDokument]'
				SET @SQL = @SQL + ', [Calculated]'
				SET @SQL = @SQL + ' FROM [fin].[tblKnjizenjeStavka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDKonto],'
				SET @SQL = @SQL + ' [IDOrganizacija],'
				SET @SQL = @SQL + ' [IDVrstaFinDokumenta],'
				SET @SQL = @SQL + ' [DatumDokumentaOriginal],'
				SET @SQL = @SQL + ' [DatumDokumentaPromjenjen],'
				SET @SQL = @SQL + ' [Nalog],'
				SET @SQL = @SQL + ' [OpisKnjizenja],'
				SET @SQL = @SQL + ' [Dug],'
				SET @SQL = @SQL + ' [Pot],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [SifraOriginalnogDokumenta],'
				SET @SQL = @SQL + ' [DatumDospijeca],'
				SET @SQL = @SQL + ' [PlacanjeModel],'
				SET @SQL = @SQL + ' [PlacanjePoziv],'
				SET @SQL = @SQL + ' [IDKnjizenja],'
				SET @SQL = @SQL + ' [DatumCreated],'
				SET @SQL = @SQL + ' [DatumModified],'
				SET @SQL = @SQL + ' [IDUserCreated],'
				SET @SQL = @SQL + ' [IDUserModified],'
				SET @SQL = @SQL + ' [PrikazUKnjizi],'
				SET @SQL = @SQL + ' [DateUICreated],'
				SET @SQL = @SQL + ' [KontoSifraPrijenos],'
				SET @SQL = @SQL + ' [IDDokument],'
				SET @SQL = @SQL + ' [Calculated]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblKnjizenjeStavka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblKnjizenjeStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_Insert
(

	@ID int    OUTPUT,

	@IDKonto int   ,

	@IDOrganizacija int   ,

	@IDVrstaFinDokumenta int   ,

	@DatumDokumentaOriginal datetime   ,

	@DatumDokumentaPromjenjen datetime   ,

	@Nalog nvarchar (50)  ,

	@OpisKnjizenja nvarchar (250)  ,

	@Dug money   ,

	@Pot money   ,

	@IDKlijent int   ,

	@SifraOriginalnogDokumenta nvarchar (50)  ,

	@DatumDospijeca datetime   ,

	@PlacanjeModel varchar (2)  ,

	@PlacanjePoziv varchar (23)  ,

	@IDKnjizenja int   ,

	@DatumCreated datetime   ,

	@DatumModified datetime   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@PrikazUKnjizi int   ,

	@DateUICreated datetime   ,

	@KontoSifraPrijenos varchar (9)  ,

	@IDDokument int   ,

	@Calculated nvarchar (31)   OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblKnjizenjeStavka]
					(
					[IDKonto]
					,[IDOrganizacija]
					,[IDVrstaFinDokumenta]
					,[DatumDokumentaOriginal]
					,[DatumDokumentaPromjenjen]
					,[Nalog]
					,[OpisKnjizenja]
					,[Dug]
					,[Pot]
					,[IDKlijent]
					,[SifraOriginalnogDokumenta]
					,[DatumDospijeca]
					,[PlacanjeModel]
					,[PlacanjePoziv]
					,[IDKnjizenja]
					,[DatumCreated]
					,[DatumModified]
					,[IDUserCreated]
					,[IDUserModified]
					,[PrikazUKnjizi]
					,[DateUICreated]
					,[KontoSifraPrijenos]
					,[IDDokument]
					)
				VALUES
					(
					@IDKonto
					,@IDOrganizacija
					,@IDVrstaFinDokumenta
					,@DatumDokumentaOriginal
					,@DatumDokumentaPromjenjen
					,@Nalog
					,@OpisKnjizenja
					,@Dug
					,@Pot
					,@IDKlijent
					,@SifraOriginalnogDokumenta
					,@DatumDospijeca
					,@PlacanjeModel
					,@PlacanjePoziv
					,@IDKnjizenja
					,@DatumCreated
					,@DatumModified
					,@IDUserCreated
					,@IDUserModified
					,@PrikazUKnjizi
					,@DateUICreated
					,@KontoSifraPrijenos
					,@IDDokument
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
				-- Select computed columns into output parameters
				SELECT
 @Calculated = [Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
[ID] = @ID 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblKnjizenjeStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_Update
(

	@ID int   ,

	@IDKonto int   ,

	@IDOrganizacija int   ,

	@IDVrstaFinDokumenta int   ,

	@DatumDokumentaOriginal datetime   ,

	@DatumDokumentaPromjenjen datetime   ,

	@Nalog nvarchar (50)  ,

	@OpisKnjizenja nvarchar (250)  ,

	@Dug money   ,

	@Pot money   ,

	@IDKlijent int   ,

	@SifraOriginalnogDokumenta nvarchar (50)  ,

	@DatumDospijeca datetime   ,

	@PlacanjeModel varchar (2)  ,

	@PlacanjePoziv varchar (23)  ,

	@IDKnjizenja int   ,

	@DatumCreated datetime   ,

	@DatumModified datetime   ,

	@IDUserCreated int   ,

	@IDUserModified int   ,

	@PrikazUKnjizi int   ,

	@DateUICreated datetime   ,

	@KontoSifraPrijenos varchar (9)  ,

	@IDDokument int   ,

	@Calculated nvarchar (31)   OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblKnjizenjeStavka]
				SET
					[IDKonto] = @IDKonto
					,[IDOrganizacija] = @IDOrganizacija
					,[IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
					,[DatumDokumentaOriginal] = @DatumDokumentaOriginal
					,[DatumDokumentaPromjenjen] = @DatumDokumentaPromjenjen
					,[Nalog] = @Nalog
					,[OpisKnjizenja] = @OpisKnjizenja
					,[Dug] = @Dug
					,[Pot] = @Pot
					,[IDKlijent] = @IDKlijent
					,[SifraOriginalnogDokumenta] = @SifraOriginalnogDokumenta
					,[DatumDospijeca] = @DatumDospijeca
					,[PlacanjeModel] = @PlacanjeModel
					,[PlacanjePoziv] = @PlacanjePoziv
					,[IDKnjizenja] = @IDKnjizenja
					,[DatumCreated] = @DatumCreated
					,[DatumModified] = @DatumModified
					,[IDUserCreated] = @IDUserCreated
					,[IDUserModified] = @IDUserModified
					,[PrikazUKnjizi] = @PrikazUKnjizi
					,[DateUICreated] = @DateUICreated
					,[KontoSifraPrijenos] = @KontoSifraPrijenos
					,[IDDokument] = @IDDokument
				WHERE
[ID] = @ID 
				
				
				-- Select computed columns into output parameters
				SELECT
 @Calculated = [Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
[ID] = @ID 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblKnjizenjeStavka table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblKnjizenjeStavka] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDUserCreated procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDUserCreated') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDUserCreated
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDUserCreated
(

	@IDUserCreated int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDUserCreated] = @IDUserCreated
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDUserModified procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDUserModified') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDUserModified
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDUserModified
(

	@IDUserModified int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDUserModified] = @IDUserModified
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDDokument procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDDokument') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDDokument
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDDokument
(

	@IDDokument int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDDokument] = @IDDokument
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKlijent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKlijent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKlijent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKlijent
(

	@IDKlijent int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKlijent] = @IDKlijent
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKnjizenja procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKnjizenja') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKnjizenja
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKnjizenja
(

	@IDKnjizenja int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKnjizenja] = @IDKnjizenja
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDOrganizacija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDOrganizacija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDOrganizacija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDOrganizacija
(

	@IDOrganizacija int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDOrganizacija] = @IDOrganizacija
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDVrstaFinDokumenta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDVrstaFinDokumenta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDVrstaFinDokumenta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDVrstaFinDokumenta
(

	@IDVrstaFinDokumenta int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDDatumDokumentaOriginalOpisKnjizenjaDugPotPlacanjeModelPlacanjePozivIDKlijent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDDatumDokumentaOriginalOpisKnjizenjaDugPotPlacanjeModelPlacanjePozivIDKlijent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDDatumDokumentaOriginalOpisKnjizenjaDugPotPlacanjeModelPlacanjePozivIDKlijent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDDatumDokumentaOriginalOpisKnjizenjaDugPotPlacanjeModelPlacanjePozivIDKlijent
(

	@ID int   ,

	@DatumDokumentaOriginal datetime   ,

	@OpisKnjizenja nvarchar (250)  ,

	@Dug money   ,

	@Pot money   ,

	@PlacanjeModel varchar (2)  ,

	@PlacanjePoziv varchar (23)  ,

	@IDKlijent int   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[ID] = @ID
					AND [DatumDokumentaOriginal] = @DatumDokumentaOriginal
					AND [OpisKnjizenja] = @OpisKnjizenja
					AND [Dug] = @Dug
					AND [Pot] = @Pot
					AND [PlacanjeModel] = @PlacanjeModel
					AND [PlacanjePoziv] = @PlacanjePoziv
					AND [IDKlijent] = @IDKlijent
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKlijentIDPotDug procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKlijentIDPotDug') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKlijentIDPotDug
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKlijentIDPotDug
(

	@IDKlijent int   ,

	@ID int   ,

	@Pot money   ,

	@Dug money   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKlijent] = @IDKlijent
					AND [ID] = @ID
					AND [Pot] = @Pot
					AND [Dug] = @Dug
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKlijentIDKontoIDOrganizacijaDatumDokumentaOriginalIDVrstaFinDokumenta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKlijentIDKontoIDOrganizacijaDatumDokumentaOriginalIDVrstaFinDokumenta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKlijentIDKontoIDOrganizacijaDatumDokumentaOriginalIDVrstaFinDokumenta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKlijentIDKontoIDOrganizacijaDatumDokumentaOriginalIDVrstaFinDokumenta
(

	@IDKlijent int   ,

	@IDKonto int   ,

	@IDOrganizacija int   ,

	@DatumDokumentaOriginal datetime   ,

	@IDVrstaFinDokumenta int   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKlijent] = @IDKlijent
					AND [IDKonto] = @IDKonto
					AND [IDOrganizacija] = @IDOrganizacija
					AND [DatumDokumentaOriginal] = @DatumDokumentaOriginal
					AND [IDVrstaFinDokumenta] = @IDVrstaFinDokumenta
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKonto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKonto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKonto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKonto
(

	@IDKonto int   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKonto] = @IDKonto
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKontoIDIDKlijentIDKnjizenjaIDOrganizacijaPotDugPrikazUKnjiziSifraOriginalnogDokumenta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKontoIDIDKlijentIDKnjizenjaIDOrganizacijaPotDugPrikazUKnjiziSifraOriginalnogDokumenta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKontoIDIDKlijentIDKnjizenjaIDOrganizacijaPotDugPrikazUKnjiziSifraOriginalnogDokumenta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKontoIDIDKlijentIDKnjizenjaIDOrganizacijaPotDugPrikazUKnjiziSifraOriginalnogDokumenta
(

	@IDKonto int   ,

	@ID int   ,

	@IDKlijent int   ,

	@IDKnjizenja int   ,

	@IDOrganizacija int   ,

	@Pot money   ,

	@Dug money   ,

	@PrikazUKnjizi int   ,

	@SifraOriginalnogDokumenta nvarchar (50)  
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKonto] = @IDKonto
					AND [ID] = @ID
					AND [IDKlijent] = @IDKlijent
					AND [IDKnjizenja] = @IDKnjizenja
					AND [IDOrganizacija] = @IDOrganizacija
					AND [Pot] = @Pot
					AND [Dug] = @Dug
					AND [PrikazUKnjizi] = @PrikazUKnjizi
					AND [SifraOriginalnogDokumenta] = @SifraOriginalnogDokumenta
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKontoIDKlijentIDOrganizacija procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKontoIDKlijentIDOrganizacija') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKontoIDKlijentIDOrganizacija
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKontoIDKlijentIDOrganizacija
(

	@IDKonto int   ,

	@IDKlijent int   ,

	@IDOrganizacija int   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKonto] = @IDKonto
					AND [IDKlijent] = @IDKlijent
					AND [IDOrganizacija] = @IDOrganizacija
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKontoDugPotIDIDKlijentIDKnjizenjaPrikazUKnjizi procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKontoDugPotIDIDKlijentIDKnjizenjaPrikazUKnjizi') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKontoDugPotIDIDKlijentIDKnjizenjaPrikazUKnjizi
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKontoDugPotIDIDKlijentIDKnjizenjaPrikazUKnjizi
(

	@IDKonto int   ,

	@Dug money   ,

	@Pot money   ,

	@ID int   ,

	@IDKlijent int   ,

	@IDKnjizenja int   ,

	@PrikazUKnjizi int   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKonto] = @IDKonto
					AND [Dug] = @Dug
					AND [Pot] = @Pot
					AND [ID] = @ID
					AND [IDKlijent] = @IDKlijent
					AND [IDKnjizenja] = @IDKnjizenja
					AND [PrikazUKnjizi] = @PrikazUKnjizi
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByPrikazUKnjiziIDKlijentIDKnjizenjaIDOrganizacijaIDKontoPotDugSifraOriginalnogDokumenta procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByPrikazUKnjiziIDKlijentIDKnjizenjaIDOrganizacijaIDKontoPotDugSifraOriginalnogDokumenta') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByPrikazUKnjiziIDKlijentIDKnjizenjaIDOrganizacijaIDKontoPotDugSifraOriginalnogDokumenta
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByPrikazUKnjiziIDKlijentIDKnjizenjaIDOrganizacijaIDKontoPotDugSifraOriginalnogDokumenta
(

	@PrikazUKnjizi int   ,

	@IDKlijent int   ,

	@IDKnjizenja int   ,

	@IDOrganizacija int   ,

	@IDKonto int   ,

	@Pot money   ,

	@Dug money   ,

	@SifraOriginalnogDokumenta nvarchar (50)  
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[PrikazUKnjizi] = @PrikazUKnjizi
					AND [IDKlijent] = @IDKlijent
					AND [IDKnjizenja] = @IDKnjizenja
					AND [IDOrganizacija] = @IDOrganizacija
					AND [IDKonto] = @IDKonto
					AND [Pot] = @Pot
					AND [Dug] = @Dug
					AND [SifraOriginalnogDokumenta] = @SifraOriginalnogDokumenta
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByPlacanjePozivPlacanjeModelID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByPlacanjePozivPlacanjeModelID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByPlacanjePozivPlacanjeModelID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByPlacanjePozivPlacanjeModelID
(

	@PlacanjePoziv varchar (23)  ,

	@PlacanjeModel varchar (2)  ,

	@ID int   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[PlacanjePoziv] = @PlacanjePoziv
					AND [PlacanjeModel] = @PlacanjeModel
					AND [ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDPotDug procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDPotDug') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDPotDug
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDPotDug
(

	@ID int   ,

	@Pot money   ,

	@Dug money   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[ID] = @ID
					AND [Pot] = @Pot
					AND [Dug] = @Dug
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDDugPot procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDDugPot') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDDugPot
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDDugPot
(

	@ID int   ,

	@Dug money   ,

	@Pot money   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[ID] = @ID
					AND [Dug] = @Dug
					AND [Pot] = @Pot
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKlijentPotDugID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKlijentPotDugID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKlijentPotDugID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKlijentPotDugID
(

	@IDKlijent int   ,

	@Pot money   ,

	@Dug money   ,

	@ID int   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKlijent] = @IDKlijent
					AND [Pot] = @Pot
					AND [Dug] = @Dug
					AND [ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKnjizenjaPotIDDugIDKlijentIDKonto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKnjizenjaPotIDDugIDKlijentIDKonto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKnjizenjaPotIDDugIDKlijentIDKonto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKnjizenjaPotIDDugIDKlijentIDKonto
(

	@IDKnjizenja int   ,

	@Pot money   ,

	@ID int   ,

	@Dug money   ,

	@IDKlijent int   ,

	@IDKonto int   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKnjizenja] = @IDKnjizenja
					AND [Pot] = @Pot
					AND [ID] = @ID
					AND [Dug] = @Dug
					AND [IDKlijent] = @IDKlijent
					AND [IDKonto] = @IDKonto
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKontoIDPotDug procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKontoIDPotDug') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKontoIDPotDug
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKontoIDPotDug
(

	@IDKonto int   ,

	@ID int   ,

	@Pot money   ,

	@Dug money   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKonto] = @IDKonto
					AND [ID] = @ID
					AND [Pot] = @Pot
					AND [Dug] = @Dug
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByIDKontoDugPot procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByIDKontoDugPot') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByIDKontoDugPot
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByIDKontoDugPot
(

	@IDKonto int   ,

	@Dug money   ,

	@Pot money   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[IDKonto] = @IDKonto
					AND [Dug] = @Dug
					AND [Pot] = @Pot
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_GetByKontoSifraPrijenosIDDokumentCalculated procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_GetByKontoSifraPrijenosIDDokumentCalculated') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_GetByKontoSifraPrijenosIDDokumentCalculated
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKnjizenjeStavka table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_GetByKontoSifraPrijenosIDDokumentCalculated
(

	@KontoSifraPrijenos varchar (9)  ,

	@IDDokument int   ,

	@Calculated nvarchar (31)  
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDOrganizacija],
					[IDVrstaFinDokumenta],
					[DatumDokumentaOriginal],
					[DatumDokumentaPromjenjen],
					[Nalog],
					[OpisKnjizenja],
					[Dug],
					[Pot],
					[IDKlijent],
					[SifraOriginalnogDokumenta],
					[DatumDospijeca],
					[PlacanjeModel],
					[PlacanjePoziv],
					[IDKnjizenja],
					[DatumCreated],
					[DatumModified],
					[IDUserCreated],
					[IDUserModified],
					[PrikazUKnjizi],
					[DateUICreated],
					[KontoSifraPrijenos],
					[IDDokument],
					[Calculated]
				FROM
					[fin].[tblKnjizenjeStavka]
				WHERE
					[KontoSifraPrijenos] = @KontoSifraPrijenos
					AND [IDDokument] = @IDDokument
					AND [Calculated] = @Calculated
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKnjizenjeStavka_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKnjizenjeStavka_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKnjizenjeStavka_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblKnjizenjeStavka table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKnjizenjeStavka_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDKonto int   = null ,

	@IDOrganizacija int   = null ,

	@IDVrstaFinDokumenta int   = null ,

	@DatumDokumentaOriginal datetime   = null ,

	@DatumDokumentaPromjenjen datetime   = null ,

	@Nalog nvarchar (50)  = null ,

	@OpisKnjizenja nvarchar (250)  = null ,

	@Dug money   = null ,

	@Pot money   = null ,

	@IDKlijent int   = null ,

	@SifraOriginalnogDokumenta nvarchar (50)  = null ,

	@DatumDospijeca datetime   = null ,

	@PlacanjeModel varchar (2)  = null ,

	@PlacanjePoziv varchar (23)  = null ,

	@IDKnjizenja int   = null ,

	@DatumCreated datetime   = null ,

	@DatumModified datetime   = null ,

	@IDUserCreated int   = null ,

	@IDUserModified int   = null ,

	@PrikazUKnjizi int   = null ,

	@DateUICreated datetime   = null ,

	@KontoSifraPrijenos varchar (9)  = null ,

	@IDDokument int   = null ,

	@Calculated nvarchar (31)  = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDKonto]
	, [IDOrganizacija]
	, [IDVrstaFinDokumenta]
	, [DatumDokumentaOriginal]
	, [DatumDokumentaPromjenjen]
	, [Nalog]
	, [OpisKnjizenja]
	, [Dug]
	, [Pot]
	, [IDKlijent]
	, [SifraOriginalnogDokumenta]
	, [DatumDospijeca]
	, [PlacanjeModel]
	, [PlacanjePoziv]
	, [IDKnjizenja]
	, [DatumCreated]
	, [DatumModified]
	, [IDUserCreated]
	, [IDUserModified]
	, [PrikazUKnjizi]
	, [DateUICreated]
	, [KontoSifraPrijenos]
	, [IDDokument]
	, [Calculated]
    FROM
	[fin].[tblKnjizenjeStavka]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDKonto] = @IDKonto OR @IDKonto is null)
	AND ([IDOrganizacija] = @IDOrganizacija OR @IDOrganizacija is null)
	AND ([IDVrstaFinDokumenta] = @IDVrstaFinDokumenta OR @IDVrstaFinDokumenta is null)
	AND ([DatumDokumentaOriginal] = @DatumDokumentaOriginal OR @DatumDokumentaOriginal is null)
	AND ([DatumDokumentaPromjenjen] = @DatumDokumentaPromjenjen OR @DatumDokumentaPromjenjen is null)
	AND ([Nalog] = @Nalog OR @Nalog is null)
	AND ([OpisKnjizenja] = @OpisKnjizenja OR @OpisKnjizenja is null)
	AND ([Dug] = @Dug OR @Dug is null)
	AND ([Pot] = @Pot OR @Pot is null)
	AND ([IDKlijent] = @IDKlijent OR @IDKlijent is null)
	AND ([SifraOriginalnogDokumenta] = @SifraOriginalnogDokumenta OR @SifraOriginalnogDokumenta is null)
	AND ([DatumDospijeca] = @DatumDospijeca OR @DatumDospijeca is null)
	AND ([PlacanjeModel] = @PlacanjeModel OR @PlacanjeModel is null)
	AND ([PlacanjePoziv] = @PlacanjePoziv OR @PlacanjePoziv is null)
	AND ([IDKnjizenja] = @IDKnjizenja OR @IDKnjizenja is null)
	AND ([DatumCreated] = @DatumCreated OR @DatumCreated is null)
	AND ([DatumModified] = @DatumModified OR @DatumModified is null)
	AND ([IDUserCreated] = @IDUserCreated OR @IDUserCreated is null)
	AND ([IDUserModified] = @IDUserModified OR @IDUserModified is null)
	AND ([PrikazUKnjizi] = @PrikazUKnjizi OR @PrikazUKnjizi is null)
	AND ([DateUICreated] = @DateUICreated OR @DateUICreated is null)
	AND ([KontoSifraPrijenos] = @KontoSifraPrijenos OR @KontoSifraPrijenos is null)
	AND ([IDDokument] = @IDDokument OR @IDDokument is null)
	AND ([Calculated] = @Calculated OR @Calculated is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDKonto]
	, [IDOrganizacija]
	, [IDVrstaFinDokumenta]
	, [DatumDokumentaOriginal]
	, [DatumDokumentaPromjenjen]
	, [Nalog]
	, [OpisKnjizenja]
	, [Dug]
	, [Pot]
	, [IDKlijent]
	, [SifraOriginalnogDokumenta]
	, [DatumDospijeca]
	, [PlacanjeModel]
	, [PlacanjePoziv]
	, [IDKnjizenja]
	, [DatumCreated]
	, [DatumModified]
	, [IDUserCreated]
	, [IDUserModified]
	, [PrikazUKnjizi]
	, [DateUICreated]
	, [KontoSifraPrijenos]
	, [IDDokument]
	, [Calculated]
    FROM
	[fin].[tblKnjizenjeStavka]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDKonto] = @IDKonto AND @IDKonto is not null)
	OR ([IDOrganizacija] = @IDOrganizacija AND @IDOrganizacija is not null)
	OR ([IDVrstaFinDokumenta] = @IDVrstaFinDokumenta AND @IDVrstaFinDokumenta is not null)
	OR ([DatumDokumentaOriginal] = @DatumDokumentaOriginal AND @DatumDokumentaOriginal is not null)
	OR ([DatumDokumentaPromjenjen] = @DatumDokumentaPromjenjen AND @DatumDokumentaPromjenjen is not null)
	OR ([Nalog] = @Nalog AND @Nalog is not null)
	OR ([OpisKnjizenja] = @OpisKnjizenja AND @OpisKnjizenja is not null)
	OR ([Dug] = @Dug AND @Dug is not null)
	OR ([Pot] = @Pot AND @Pot is not null)
	OR ([IDKlijent] = @IDKlijent AND @IDKlijent is not null)
	OR ([SifraOriginalnogDokumenta] = @SifraOriginalnogDokumenta AND @SifraOriginalnogDokumenta is not null)
	OR ([DatumDospijeca] = @DatumDospijeca AND @DatumDospijeca is not null)
	OR ([PlacanjeModel] = @PlacanjeModel AND @PlacanjeModel is not null)
	OR ([PlacanjePoziv] = @PlacanjePoziv AND @PlacanjePoziv is not null)
	OR ([IDKnjizenja] = @IDKnjizenja AND @IDKnjizenja is not null)
	OR ([DatumCreated] = @DatumCreated AND @DatumCreated is not null)
	OR ([DatumModified] = @DatumModified AND @DatumModified is not null)
	OR ([IDUserCreated] = @IDUserCreated AND @IDUserCreated is not null)
	OR ([IDUserModified] = @IDUserModified AND @IDUserModified is not null)
	OR ([PrikazUKnjizi] = @PrikazUKnjizi AND @PrikazUKnjizi is not null)
	OR ([DateUICreated] = @DateUICreated AND @DateUICreated is not null)
	OR ([KontoSifraPrijenos] = @KontoSifraPrijenos AND @KontoSifraPrijenos is not null)
	OR ([IDDokument] = @IDDokument AND @IDDokument is not null)
	OR ([Calculated] = @Calculated AND @Calculated is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentNapomena_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentNapomena_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentNapomena_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblKlijentNapomena table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentNapomena_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[DateCreated],
					[DateModified],
					[Napomena],
					[IDUserCreated],
					[IDUserModified]
				FROM
					[dbo].[tblKlijentNapomena]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentNapomena_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentNapomena_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentNapomena_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblKlijentNapomena table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentNapomena_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [DateCreated]'
				SET @SQL = @SQL + ', [DateModified]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [IDUserCreated]'
				SET @SQL = @SQL + ', [IDUserModified]'
				SET @SQL = @SQL + ' FROM [dbo].[tblKlijentNapomena]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [DateCreated],'
				SET @SQL = @SQL + ' [DateModified],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [IDUserCreated],'
				SET @SQL = @SQL + ' [IDUserModified]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblKlijentNapomena]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentNapomena_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentNapomena_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentNapomena_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblKlijentNapomena table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentNapomena_Insert
(

	@ID int    OUTPUT,

	@IDKlijent int   ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@Napomena nvarchar (4000)  ,

	@IDUserCreated int   ,

	@IDUserModified int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblKlijentNapomena]
					(
					[IDKlijent]
					,[DateCreated]
					,[DateModified]
					,[Napomena]
					,[IDUserCreated]
					,[IDUserModified]
					)
				VALUES
					(
					@IDKlijent
					,@DateCreated
					,@DateModified
					,@Napomena
					,@IDUserCreated
					,@IDUserModified
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentNapomena_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentNapomena_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentNapomena_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblKlijentNapomena table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentNapomena_Update
(

	@ID int   ,

	@IDKlijent int   ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@Napomena nvarchar (4000)  ,

	@IDUserCreated int   ,

	@IDUserModified int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblKlijentNapomena]
				SET
					[IDKlijent] = @IDKlijent
					,[DateCreated] = @DateCreated
					,[DateModified] = @DateModified
					,[Napomena] = @Napomena
					,[IDUserCreated] = @IDUserCreated
					,[IDUserModified] = @IDUserModified
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentNapomena_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentNapomena_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentNapomena_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblKlijentNapomena table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentNapomena_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblKlijentNapomena] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentNapomena_GetByIDUserCreated procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentNapomena_GetByIDUserCreated') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentNapomena_GetByIDUserCreated
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentNapomena table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentNapomena_GetByIDUserCreated
(

	@IDUserCreated int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[DateCreated],
					[DateModified],
					[Napomena],
					[IDUserCreated],
					[IDUserModified]
				FROM
					[dbo].[tblKlijentNapomena]
				WHERE
					[IDUserCreated] = @IDUserCreated
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentNapomena_GetByIDUserModified procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentNapomena_GetByIDUserModified') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentNapomena_GetByIDUserModified
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentNapomena table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentNapomena_GetByIDUserModified
(

	@IDUserModified int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[DateCreated],
					[DateModified],
					[Napomena],
					[IDUserCreated],
					[IDUserModified]
				FROM
					[dbo].[tblKlijentNapomena]
				WHERE
					[IDUserModified] = @IDUserModified
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentNapomena_GetByIDKlijent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentNapomena_GetByIDKlijent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentNapomena_GetByIDKlijent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentNapomena table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentNapomena_GetByIDKlijent
(

	@IDKlijent int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[DateCreated],
					[DateModified],
					[Napomena],
					[IDUserCreated],
					[IDUserModified]
				FROM
					[dbo].[tblKlijentNapomena]
				WHERE
					[IDKlijent] = @IDKlijent
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentNapomena_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentNapomena_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentNapomena_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentNapomena table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentNapomena_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDKlijent],
					[DateCreated],
					[DateModified],
					[Napomena],
					[IDUserCreated],
					[IDUserModified]
				FROM
					[dbo].[tblKlijentNapomena]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentNapomena_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentNapomena_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentNapomena_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblKlijentNapomena table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentNapomena_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDKlijent int   = null ,

	@DateCreated datetime   = null ,

	@DateModified datetime   = null ,

	@Napomena nvarchar (4000)  = null ,

	@IDUserCreated int   = null ,

	@IDUserModified int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDKlijent]
	, [DateCreated]
	, [DateModified]
	, [Napomena]
	, [IDUserCreated]
	, [IDUserModified]
    FROM
	[dbo].[tblKlijentNapomena]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDKlijent] = @IDKlijent OR @IDKlijent is null)
	AND ([DateCreated] = @DateCreated OR @DateCreated is null)
	AND ([DateModified] = @DateModified OR @DateModified is null)
	AND ([Napomena] = @Napomena OR @Napomena is null)
	AND ([IDUserCreated] = @IDUserCreated OR @IDUserCreated is null)
	AND ([IDUserModified] = @IDUserModified OR @IDUserModified is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDKlijent]
	, [DateCreated]
	, [DateModified]
	, [Napomena]
	, [IDUserCreated]
	, [IDUserModified]
    FROM
	[dbo].[tblKlijentNapomena]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDKlijent] = @IDKlijent AND @IDKlijent is not null)
	OR ([DateCreated] = @DateCreated AND @DateCreated is not null)
	OR ([DateModified] = @DateModified AND @DateModified is not null)
	OR ([Napomena] = @Napomena AND @Napomena is not null)
	OR ([IDUserCreated] = @IDUserCreated AND @IDUserCreated is not null)
	OR ([IDUserModified] = @IDUserModified AND @IDUserModified is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIzvadak_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIzvadak_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIzvadak_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblIzvadak table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIzvadak_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumIzradeIzvatka],
					[BrojDepozitne],
					[Datoteka],
					[IDKnjizenje]
				FROM
					[fin].[tblIzvadak]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIzvadak_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIzvadak_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIzvadak_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblIzvadak table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIzvadak_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [DatumIzradeIzvatka]'
				SET @SQL = @SQL + ', [BrojDepozitne]'
				SET @SQL = @SQL + ', [Datoteka]'
				SET @SQL = @SQL + ', [IDKnjizenje]'
				SET @SQL = @SQL + ' FROM [fin].[tblIzvadak]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [DatumIzradeIzvatka],'
				SET @SQL = @SQL + ' [BrojDepozitne],'
				SET @SQL = @SQL + ' [Datoteka],'
				SET @SQL = @SQL + ' [IDKnjizenje]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblIzvadak]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIzvadak_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIzvadak_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIzvadak_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblIzvadak table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIzvadak_Insert
(

	@ID int    OUTPUT,

	@DatumIzradeIzvatka datetime   ,

	@BrojDepozitne int   ,

	@Datoteka varbinary (MAX)  ,

	@IDKnjizenje int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblIzvadak]
					(
					[DatumIzradeIzvatka]
					,[BrojDepozitne]
					,[Datoteka]
					,[IDKnjizenje]
					)
				VALUES
					(
					@DatumIzradeIzvatka
					,@BrojDepozitne
					,@Datoteka
					,@IDKnjizenje
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIzvadak_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIzvadak_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIzvadak_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblIzvadak table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIzvadak_Update
(

	@ID int   ,

	@DatumIzradeIzvatka datetime   ,

	@BrojDepozitne int   ,

	@Datoteka varbinary (MAX)  ,

	@IDKnjizenje int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblIzvadak]
				SET
					[DatumIzradeIzvatka] = @DatumIzradeIzvatka
					,[BrojDepozitne] = @BrojDepozitne
					,[Datoteka] = @Datoteka
					,[IDKnjizenje] = @IDKnjizenje
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIzvadak_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIzvadak_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIzvadak_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblIzvadak table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIzvadak_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblIzvadak] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIzvadak_GetByIDKnjizenje procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIzvadak_GetByIDKnjizenje') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIzvadak_GetByIDKnjizenje
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblIzvadak table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIzvadak_GetByIDKnjizenje
(

	@IDKnjizenje int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumIzradeIzvatka],
					[BrojDepozitne],
					[Datoteka],
					[IDKnjizenje]
				FROM
					[fin].[tblIzvadak]
				WHERE
					[IDKnjizenje] = @IDKnjizenje
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIzvadak_GetByDatumIzradeIzvatkaBrojDepozitne procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIzvadak_GetByDatumIzradeIzvatkaBrojDepozitne') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIzvadak_GetByDatumIzradeIzvatkaBrojDepozitne
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblIzvadak table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIzvadak_GetByDatumIzradeIzvatkaBrojDepozitne
(

	@DatumIzradeIzvatka datetime   ,

	@BrojDepozitne int   
)
AS


				SELECT
					[ID],
					[DatumIzradeIzvatka],
					[BrojDepozitne],
					[Datoteka],
					[IDKnjizenje]
				FROM
					[fin].[tblIzvadak]
				WHERE
					[DatumIzradeIzvatka] = @DatumIzradeIzvatka
					AND [BrojDepozitne] = @BrojDepozitne
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIzvadak_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIzvadak_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIzvadak_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblIzvadak table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIzvadak_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[DatumIzradeIzvatka],
					[BrojDepozitne],
					[Datoteka],
					[IDKnjizenje]
				FROM
					[fin].[tblIzvadak]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblIzvadak_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblIzvadak_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblIzvadak_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblIzvadak table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblIzvadak_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@DatumIzradeIzvatka datetime   = null ,

	@BrojDepozitne int   = null ,

	@Datoteka varbinary (MAX)  = null ,

	@IDKnjizenje int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [DatumIzradeIzvatka]
	, [BrojDepozitne]
	, [Datoteka]
	, [IDKnjizenje]
    FROM
	[fin].[tblIzvadak]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([DatumIzradeIzvatka] = @DatumIzradeIzvatka OR @DatumIzradeIzvatka is null)
	AND ([BrojDepozitne] = @BrojDepozitne OR @BrojDepozitne is null)
	AND ([IDKnjizenje] = @IDKnjizenje OR @IDKnjizenje is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [DatumIzradeIzvatka]
	, [BrojDepozitne]
	, [Datoteka]
	, [IDKnjizenje]
    FROM
	[fin].[tblIzvadak]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([DatumIzradeIzvatka] = @DatumIzradeIzvatka AND @DatumIzradeIzvatka is not null)
	OR ([BrojDepozitne] = @BrojDepozitne AND @BrojDepozitne is not null)
	OR ([IDKnjizenje] = @IDKnjizenje AND @IDKnjizenje is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentOsoba_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentOsoba_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentOsoba_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblKlijentOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentOsoba_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Ime],
					[Prezime],
					[Telefon],
					[Mobitel],
					[Fax],
					[Email],
					[IDKlijent],
					[IDMjesto]
				FROM
					[dbo].[tblKlijentOsoba]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentOsoba_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentOsoba_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentOsoba_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblKlijentOsoba table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentOsoba_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Ime]'
				SET @SQL = @SQL + ', [Prezime]'
				SET @SQL = @SQL + ', [Telefon]'
				SET @SQL = @SQL + ', [Mobitel]'
				SET @SQL = @SQL + ', [Fax]'
				SET @SQL = @SQL + ', [Email]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [IDMjesto]'
				SET @SQL = @SQL + ' FROM [dbo].[tblKlijentOsoba]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Ime],'
				SET @SQL = @SQL + ' [Prezime],'
				SET @SQL = @SQL + ' [Telefon],'
				SET @SQL = @SQL + ' [Mobitel],'
				SET @SQL = @SQL + ' [Fax],'
				SET @SQL = @SQL + ' [Email],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [IDMjesto]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblKlijentOsoba]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentOsoba_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentOsoba_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentOsoba_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblKlijentOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentOsoba_Insert
(

	@ID int    OUTPUT,

	@Ime nvarchar (100)  ,

	@Prezime nvarchar (100)  ,

	@Telefon nvarchar (50)  ,

	@Mobitel nvarchar (50)  ,

	@Fax nvarchar (50)  ,

	@Email nvarchar (50)  ,

	@IDKlijent int   ,

	@IDMjesto int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblKlijentOsoba]
					(
					[Ime]
					,[Prezime]
					,[Telefon]
					,[Mobitel]
					,[Fax]
					,[Email]
					,[IDKlijent]
					,[IDMjesto]
					)
				VALUES
					(
					@Ime
					,@Prezime
					,@Telefon
					,@Mobitel
					,@Fax
					,@Email
					,@IDKlijent
					,@IDMjesto
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentOsoba_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentOsoba_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentOsoba_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblKlijentOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentOsoba_Update
(

	@ID int   ,

	@Ime nvarchar (100)  ,

	@Prezime nvarchar (100)  ,

	@Telefon nvarchar (50)  ,

	@Mobitel nvarchar (50)  ,

	@Fax nvarchar (50)  ,

	@Email nvarchar (50)  ,

	@IDKlijent int   ,

	@IDMjesto int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblKlijentOsoba]
				SET
					[Ime] = @Ime
					,[Prezime] = @Prezime
					,[Telefon] = @Telefon
					,[Mobitel] = @Mobitel
					,[Fax] = @Fax
					,[Email] = @Email
					,[IDKlijent] = @IDKlijent
					,[IDMjesto] = @IDMjesto
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentOsoba_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentOsoba_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentOsoba_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblKlijentOsoba table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentOsoba_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblKlijentOsoba] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentOsoba_GetByIDKlijent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentOsoba_GetByIDKlijent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentOsoba_GetByIDKlijent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentOsoba table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentOsoba_GetByIDKlijent
(

	@IDKlijent int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Ime],
					[Prezime],
					[Telefon],
					[Mobitel],
					[Fax],
					[Email],
					[IDKlijent],
					[IDMjesto]
				FROM
					[dbo].[tblKlijentOsoba]
				WHERE
					[IDKlijent] = @IDKlijent
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentOsoba_GetByIDMjesto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentOsoba_GetByIDMjesto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentOsoba_GetByIDMjesto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentOsoba table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentOsoba_GetByIDMjesto
(

	@IDMjesto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Ime],
					[Prezime],
					[Telefon],
					[Mobitel],
					[Fax],
					[Email],
					[IDKlijent],
					[IDMjesto]
				FROM
					[dbo].[tblKlijentOsoba]
				WHERE
					[IDMjesto] = @IDMjesto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentOsoba_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentOsoba_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentOsoba_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentOsoba table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentOsoba_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[Ime],
					[Prezime],
					[Telefon],
					[Mobitel],
					[Fax],
					[Email],
					[IDKlijent],
					[IDMjesto]
				FROM
					[dbo].[tblKlijentOsoba]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentOsoba_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentOsoba_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentOsoba_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblKlijentOsoba table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentOsoba_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@Ime nvarchar (100)  = null ,

	@Prezime nvarchar (100)  = null ,

	@Telefon nvarchar (50)  = null ,

	@Mobitel nvarchar (50)  = null ,

	@Fax nvarchar (50)  = null ,

	@Email nvarchar (50)  = null ,

	@IDKlijent int   = null ,

	@IDMjesto int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Ime]
	, [Prezime]
	, [Telefon]
	, [Mobitel]
	, [Fax]
	, [Email]
	, [IDKlijent]
	, [IDMjesto]
    FROM
	[dbo].[tblKlijentOsoba]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([Ime] = @Ime OR @Ime is null)
	AND ([Prezime] = @Prezime OR @Prezime is null)
	AND ([Telefon] = @Telefon OR @Telefon is null)
	AND ([Mobitel] = @Mobitel OR @Mobitel is null)
	AND ([Fax] = @Fax OR @Fax is null)
	AND ([Email] = @Email OR @Email is null)
	AND ([IDKlijent] = @IDKlijent OR @IDKlijent is null)
	AND ([IDMjesto] = @IDMjesto OR @IDMjesto is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Ime]
	, [Prezime]
	, [Telefon]
	, [Mobitel]
	, [Fax]
	, [Email]
	, [IDKlijent]
	, [IDMjesto]
    FROM
	[dbo].[tblKlijentOsoba]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([Ime] = @Ime AND @Ime is not null)
	OR ([Prezime] = @Prezime AND @Prezime is not null)
	OR ([Telefon] = @Telefon AND @Telefon is not null)
	OR ([Mobitel] = @Mobitel AND @Mobitel is not null)
	OR ([Fax] = @Fax AND @Fax is not null)
	OR ([Email] = @Email AND @Email is not null)
	OR ([IDKlijent] = @IDKlijent AND @IDKlijent is not null)
	OR ([IDMjesto] = @IDMjesto AND @IDMjesto is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentBankovniRacun_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentBankovniRacun_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentBankovniRacun_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblKlijentBankovniRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentBankovniRacun_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[ZiroRacun],
					[IBAN],
					[SWIFT],
					[Ostalo],
					[IsDefault],
					[Calculated]
				FROM
					[dbo].[tblKlijentBankovniRacun]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentBankovniRacun_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentBankovniRacun_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentBankovniRacun_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblKlijentBankovniRacun table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentBankovniRacun_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [ZiroRacun]'
				SET @SQL = @SQL + ', [IBAN]'
				SET @SQL = @SQL + ', [SWIFT]'
				SET @SQL = @SQL + ', [Ostalo]'
				SET @SQL = @SQL + ', [IsDefault]'
				SET @SQL = @SQL + ', [Calculated]'
				SET @SQL = @SQL + ' FROM [dbo].[tblKlijentBankovniRacun]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [ZiroRacun],'
				SET @SQL = @SQL + ' [IBAN],'
				SET @SQL = @SQL + ' [SWIFT],'
				SET @SQL = @SQL + ' [Ostalo],'
				SET @SQL = @SQL + ' [IsDefault],'
				SET @SQL = @SQL + ' [Calculated]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblKlijentBankovniRacun]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentBankovniRacun_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentBankovniRacun_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentBankovniRacun_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblKlijentBankovniRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentBankovniRacun_Insert
(

	@ID int    OUTPUT,

	@IDKlijent int   ,

	@ZiroRacun varchar (18)  ,

	@IBAN nvarchar (30)  ,

	@SWIFT nvarchar (30)  ,

	@Ostalo nvarchar (30)  ,

	@IsDefault bit   ,

	@Calculated int    OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [dbo].[tblKlijentBankovniRacun]
					(
					[IDKlijent]
					,[ZiroRacun]
					,[IBAN]
					,[SWIFT]
					,[Ostalo]
					,[IsDefault]
					)
				VALUES
					(
					@IDKlijent
					,@ZiroRacun
					,@IBAN
					,@SWIFT
					,@Ostalo
					,@IsDefault
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
				-- Select computed columns into output parameters
				SELECT
 @Calculated = [Calculated]
				FROM
					[dbo].[tblKlijentBankovniRacun]
				WHERE
[ID] = @ID 
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentBankovniRacun_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentBankovniRacun_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentBankovniRacun_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblKlijentBankovniRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentBankovniRacun_Update
(

	@ID int   ,

	@IDKlijent int   ,

	@ZiroRacun varchar (18)  ,

	@IBAN nvarchar (30)  ,

	@SWIFT nvarchar (30)  ,

	@Ostalo nvarchar (30)  ,

	@IsDefault bit   ,

	@Calculated int    OUTPUT
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblKlijentBankovniRacun]
				SET
					[IDKlijent] = @IDKlijent
					,[ZiroRacun] = @ZiroRacun
					,[IBAN] = @IBAN
					,[SWIFT] = @SWIFT
					,[Ostalo] = @Ostalo
					,[IsDefault] = @IsDefault
				WHERE
[ID] = @ID 
				
				
				-- Select computed columns into output parameters
				SELECT
 @Calculated = [Calculated]
				FROM
					[dbo].[tblKlijentBankovniRacun]
				WHERE
[ID] = @ID 
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentBankovniRacun_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentBankovniRacun_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentBankovniRacun_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblKlijentBankovniRacun table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentBankovniRacun_Delete
(

	@ID int   
)
AS


				DELETE FROM [dbo].[tblKlijentBankovniRacun] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentBankovniRacun_GetByIDKlijent procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentBankovniRacun_GetByIDKlijent') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentBankovniRacun_GetByIDKlijent
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentBankovniRacun table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentBankovniRacun_GetByIDKlijent
(

	@IDKlijent int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[ZiroRacun],
					[IBAN],
					[SWIFT],
					[Ostalo],
					[IsDefault],
					[Calculated]
				FROM
					[dbo].[tblKlijentBankovniRacun]
				WHERE
					[IDKlijent] = @IDKlijent
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentBankovniRacun_GetByIsDefaultCalculated procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentBankovniRacun_GetByIsDefaultCalculated') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentBankovniRacun_GetByIsDefaultCalculated
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentBankovniRacun table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentBankovniRacun_GetByIsDefaultCalculated
(

	@IsDefault bit   ,

	@Calculated int   
)
AS


				SELECT
					[ID],
					[IDKlijent],
					[ZiroRacun],
					[IBAN],
					[SWIFT],
					[Ostalo],
					[IsDefault],
					[Calculated]
				FROM
					[dbo].[tblKlijentBankovniRacun]
				WHERE
					[IsDefault] = @IsDefault
					AND [Calculated] = @Calculated
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentBankovniRacun_GetByZiroRacun procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentBankovniRacun_GetByZiroRacun') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentBankovniRacun_GetByZiroRacun
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentBankovniRacun table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentBankovniRacun_GetByZiroRacun
(

	@ZiroRacun varchar (18)  
)
AS


				SELECT
					[ID],
					[IDKlijent],
					[ZiroRacun],
					[IBAN],
					[SWIFT],
					[Ostalo],
					[IsDefault],
					[Calculated]
				FROM
					[dbo].[tblKlijentBankovniRacun]
				WHERE
					[ZiroRacun] = @ZiroRacun
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentBankovniRacun_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentBankovniRacun_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentBankovniRacun_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKlijentBankovniRacun table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentBankovniRacun_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDKlijent],
					[ZiroRacun],
					[IBAN],
					[SWIFT],
					[Ostalo],
					[IsDefault],
					[Calculated]
				FROM
					[dbo].[tblKlijentBankovniRacun]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.tblKlijentBankovniRacun_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblKlijentBankovniRacun_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblKlijentBankovniRacun_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblKlijentBankovniRacun table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblKlijentBankovniRacun_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDKlijent int   = null ,

	@ZiroRacun varchar (18)  = null ,

	@IBAN nvarchar (30)  = null ,

	@SWIFT nvarchar (30)  = null ,

	@Ostalo nvarchar (30)  = null ,

	@IsDefault bit   = null ,

	@Calculated int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDKlijent]
	, [ZiroRacun]
	, [IBAN]
	, [SWIFT]
	, [Ostalo]
	, [IsDefault]
	, [Calculated]
    FROM
	[dbo].[tblKlijentBankovniRacun]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDKlijent] = @IDKlijent OR @IDKlijent is null)
	AND ([ZiroRacun] = @ZiroRacun OR @ZiroRacun is null)
	AND ([IBAN] = @IBAN OR @IBAN is null)
	AND ([SWIFT] = @SWIFT OR @SWIFT is null)
	AND ([Ostalo] = @Ostalo OR @Ostalo is null)
	AND ([IsDefault] = @IsDefault OR @IsDefault is null)
	AND ([Calculated] = @Calculated OR @Calculated is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDKlijent]
	, [ZiroRacun]
	, [IBAN]
	, [SWIFT]
	, [Ostalo]
	, [IsDefault]
	, [Calculated]
    FROM
	[dbo].[tblKlijentBankovniRacun]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDKlijent] = @IDKlijent AND @IDKlijent is not null)
	OR ([ZiroRacun] = @ZiroRacun AND @ZiroRacun is not null)
	OR ([IBAN] = @IBAN AND @IBAN is not null)
	OR ([SWIFT] = @SWIFT AND @SWIFT is not null)
	OR ([Ostalo] = @Ostalo AND @Ostalo is not null)
	OR ([IsDefault] = @IsDefault AND @IsDefault is not null)
	OR ([Calculated] = @Calculated AND @Calculated is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKontoKolona_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKontoKolona_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKontoKolona_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblKontoKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKontoKolona_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDIspisKolona]
				FROM
					[fin].[tblKontoKolona]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKontoKolona_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKontoKolona_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKontoKolona_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblKontoKolona table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKontoKolona_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDKonto]'
				SET @SQL = @SQL + ', [IDIspisKolona]'
				SET @SQL = @SQL + ' FROM [fin].[tblKontoKolona]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDKonto],'
				SET @SQL = @SQL + ' [IDIspisKolona]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblKontoKolona]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKontoKolona_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKontoKolona_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKontoKolona_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblKontoKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKontoKolona_Insert
(

	@ID int    OUTPUT,

	@IDKonto int   ,

	@IDIspisKolona int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblKontoKolona]
					(
					[IDKonto]
					,[IDIspisKolona]
					)
				VALUES
					(
					@IDKonto
					,@IDIspisKolona
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKontoKolona_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKontoKolona_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKontoKolona_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblKontoKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKontoKolona_Update
(

	@ID int   ,

	@IDKonto int   ,

	@IDIspisKolona int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblKontoKolona]
				SET
					[IDKonto] = @IDKonto
					,[IDIspisKolona] = @IDIspisKolona
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKontoKolona_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKontoKolona_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKontoKolona_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblKontoKolona table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKontoKolona_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblKontoKolona] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKontoKolona_GetByIDIspisKolona procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKontoKolona_GetByIDIspisKolona') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKontoKolona_GetByIDIspisKolona
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKontoKolona table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKontoKolona_GetByIDIspisKolona
(

	@IDIspisKolona int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDIspisKolona]
				FROM
					[fin].[tblKontoKolona]
				WHERE
					[IDIspisKolona] = @IDIspisKolona
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKontoKolona_GetByIDKonto procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKontoKolona_GetByIDKonto') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKontoKolona_GetByIDKonto
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKontoKolona table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKontoKolona_GetByIDKonto
(

	@IDKonto int   
)
AS


				SET ANSI_NULLS OFF
				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKonto],
					[IDIspisKolona]
				FROM
					[fin].[tblKontoKolona]
				WHERE
					[IDKonto] = @IDKonto
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKontoKolona_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKontoKolona_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKontoKolona_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblKontoKolona table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKontoKolona_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDKonto],
					[IDIspisKolona]
				FROM
					[fin].[tblKontoKolona]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblKontoKolona_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblKontoKolona_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblKontoKolona_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblKontoKolona table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblKontoKolona_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDKonto int   = null ,

	@IDIspisKolona int   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDKonto]
	, [IDIspisKolona]
    FROM
	[fin].[tblKontoKolona]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDKonto] = @IDKonto OR @IDKonto is null)
	AND ([IDIspisKolona] = @IDIspisKolona OR @IDIspisKolona is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDKonto]
	, [IDIspisKolona]
    FROM
	[fin].[tblKontoKolona]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDKonto] = @IDKonto AND @IDKonto is not null)
	OR ([IDIspisKolona] = @IDIspisKolona AND @IDIspisKolona is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the tblZatvaranje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKnjizenje],
					[IDZatvaratelj],
					[IznosZatvaratelja]
				FROM
					[fin].[tblZatvaranje]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the tblZatvaranje table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDKnjizenje]'
				SET @SQL = @SQL + ', [IDZatvaratelj]'
				SET @SQL = @SQL + ', [IznosZatvaratelja]'
				SET @SQL = @SQL + ' FROM [fin].[tblZatvaranje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDKnjizenje],'
				SET @SQL = @SQL + ' [IDZatvaratelj],'
				SET @SQL = @SQL + ' [IznosZatvaratelja]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[tblZatvaranje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Inserts a record into the tblZatvaranje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_Insert
(

	@ID int    OUTPUT,

	@IDKnjizenje int   ,

	@IDZatvaratelj int   ,

	@IznosZatvaratelja money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED	
				INSERT INTO [fin].[tblZatvaranje]
					(
					[IDKnjizenje]
					,[IDZatvaratelj]
					,[IznosZatvaratelja]
					)
				VALUES
					(
					@IDKnjizenje
					,@IDZatvaratelj
					,@IznosZatvaratelja
					)
				
				-- Get the identity value
				SET @ID = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Updates a record in the tblZatvaranje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_Update
(

	@ID int   ,

	@IDKnjizenje int   ,

	@IDZatvaratelj int   ,

	@IznosZatvaratelja money   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				
				-- Modify the updatable columns
				UPDATE
					[fin].[tblZatvaranje]
				SET
					[IDKnjizenje] = @IDKnjizenje
					,[IDZatvaratelj] = @IDZatvaratelj
					,[IznosZatvaratelja] = @IznosZatvaratelja
				WHERE
[ID] = @ID 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Deletes a record in the tblZatvaranje table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_Delete
(

	@ID int   
)
AS


				DELETE FROM [fin].[tblZatvaranje] WITH (ROWLOCK) 
				WHERE
					[ID] = @ID
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_GetByIDKnjizenjeIDZatvarateljIznosZatvaratelja procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_GetByIDKnjizenjeIDZatvarateljIznosZatvaratelja') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_GetByIDKnjizenjeIDZatvarateljIznosZatvaratelja
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblZatvaranje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_GetByIDKnjizenjeIDZatvarateljIznosZatvaratelja
(

	@IDKnjizenje int   ,

	@IDZatvaratelj int   ,

	@IznosZatvaratelja money   
)
AS


				SELECT
					[ID],
					[IDKnjizenje],
					[IDZatvaratelj],
					[IznosZatvaratelja]
				FROM
					[fin].[tblZatvaranje]
				WHERE
					[IDKnjizenje] = @IDKnjizenje
					AND [IDZatvaratelj] = @IDZatvaratelj
					AND [IznosZatvaratelja] = @IznosZatvaratelja
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_GetByIDZatvarateljIDKnjizenjeIznosZatvaratelja procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_GetByIDZatvarateljIDKnjizenjeIznosZatvaratelja') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_GetByIDZatvarateljIDKnjizenjeIznosZatvaratelja
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblZatvaranje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_GetByIDZatvarateljIDKnjizenjeIznosZatvaratelja
(

	@IDZatvaratelj int   ,

	@IDKnjizenje int   ,

	@IznosZatvaratelja money   
)
AS


				SELECT
					[ID],
					[IDKnjizenje],
					[IDZatvaratelj],
					[IznosZatvaratelja]
				FROM
					[fin].[tblZatvaranje]
				WHERE
					[IDZatvaratelj] = @IDZatvaratelj
					AND [IDKnjizenje] = @IDKnjizenje
					AND [IznosZatvaratelja] = @IznosZatvaratelja
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_GetByIDKnjizenje procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_GetByIDKnjizenje') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_GetByIDKnjizenje
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblZatvaranje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_GetByIDKnjizenje
(

	@IDKnjizenje int   
)
AS


				SELECT
					[ID],
					[IDKnjizenje],
					[IDZatvaratelj],
					[IznosZatvaratelja]
				FROM
					[fin].[tblZatvaranje]
				WHERE
					[IDKnjizenje] = @IDKnjizenje
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_GetByIDZatvaratelj procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_GetByIDZatvaratelj') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_GetByIDZatvaratelj
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblZatvaranje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_GetByIDZatvaratelj
(

	@IDZatvaratelj int   
)
AS


				SELECT
					[ID],
					[IDKnjizenje],
					[IDZatvaratelj],
					[IznosZatvaratelja]
				FROM
					[fin].[tblZatvaranje]
				WHERE
					[IDZatvaratelj] = @IDZatvaratelj
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_GetByID procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_GetByID') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_GetByID
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Select records from the tblZatvaranje table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_GetByID
(

	@ID int   
)
AS


				SELECT
					[ID],
					[IDKnjizenje],
					[IDZatvaratelj],
					[IznosZatvaratelja]
				FROM
					[fin].[tblZatvaranje]
				WHERE
					[ID] = @ID
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.tblZatvaranje_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.tblZatvaranje_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.tblZatvaranje_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Finds records in the tblZatvaranje table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.tblZatvaranje_Find
(

	@SearchUsingOR bit   = null ,

	@ID int   = null ,

	@IDKnjizenje int   = null ,

	@IDZatvaratelj int   = null ,

	@IznosZatvaratelja money   = null 
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [IDKnjizenje]
	, [IDZatvaratelj]
	, [IznosZatvaratelja]
    FROM
	[fin].[tblZatvaranje]
    WHERE 
	 ([ID] = @ID OR @ID is null)
	AND ([IDKnjizenje] = @IDKnjizenje OR @IDKnjizenje is null)
	AND ([IDZatvaratelj] = @IDZatvaratelj OR @IDZatvaratelj is null)
	AND ([IznosZatvaratelja] = @IznosZatvaratelja OR @IznosZatvaratelja is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [IDKnjizenje]
	, [IDZatvaratelj]
	, [IznosZatvaratelja]
    FROM
	[fin].[tblZatvaranje]
    WHERE 
	 ([ID] = @ID AND @ID is not null)
	OR ([IDKnjizenje] = @IDKnjizenje AND @IDKnjizenje is not null)
	OR ([IDZatvaratelj] = @IDZatvaratelj AND @IDZatvaratelj is not null)
	OR ([IznosZatvaratelja] = @IznosZatvaratelja AND @IznosZatvaratelja is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwArtiklKategorija_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwArtiklKategorija_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwArtiklKategorija_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwArtiklKategorija view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwArtiklKategorija_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[Hierarchy],
					[Put],
					[IDRoditelj],
					[Abstraktna],
					[Lvl]
				FROM
					[dbo].[vwArtiklKategorija]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwArtiklKategorija_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwArtiklKategorija_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwArtiklKategorija_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwArtiklKategorija view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwArtiklKategorija_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Hierarchy]'
				SET @SQL = @SQL + ', [Put]'
				SET @SQL = @SQL + ', [IDRoditelj]'
				SET @SQL = @SQL + ', [Abstraktna]'
				SET @SQL = @SQL + ', [Lvl]'
				SET @SQL = @SQL + ' FROM [dbo].[vwArtiklKategorija]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Hierarchy],'
				SET @SQL = @SQL + ' [Put],'
				SET @SQL = @SQL + ' [IDRoditelj],'
				SET @SQL = @SQL + ' [Abstraktna],'
				SET @SQL = @SQL + ' [Lvl]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwArtiklKategorija]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwArtiklStanjeuSkladistu_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwArtiklStanjeuSkladistu_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwArtiklStanjeuSkladistu_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwArtiklStanjeuSkladistu view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwArtiklStanjeuSkladistu_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDArtikl],
					[Artikl],
					[IDSkladiste],
					[Skladiste],
					[Stanje],
					[Rezervirano],
					[Predracun],
					[IDOrganizacijaOd],
					[VPC],
					[MPC]
				FROM
					[dbo].[vwArtiklStanjeuSkladistu]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwArtiklStanjeuSkladistu_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwArtiklStanjeuSkladistu_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwArtiklStanjeuSkladistu_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwArtiklStanjeuSkladistu view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwArtiklStanjeuSkladistu_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDArtikl]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDArtikl]'
				SET @SQL = @SQL + ', [Artikl]'
				SET @SQL = @SQL + ', [IDSkladiste]'
				SET @SQL = @SQL + ', [Skladiste]'
				SET @SQL = @SQL + ', [Stanje]'
				SET @SQL = @SQL + ', [Rezervirano]'
				SET @SQL = @SQL + ', [Predracun]'
				SET @SQL = @SQL + ', [IDOrganizacijaOd]'
				SET @SQL = @SQL + ', [VPC]'
				SET @SQL = @SQL + ', [MPC]'
				SET @SQL = @SQL + ' FROM [dbo].[vwArtiklStanjeuSkladistu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDArtikl],'
				SET @SQL = @SQL + ' [Artikl],'
				SET @SQL = @SQL + ' [IDSkladiste],'
				SET @SQL = @SQL + ' [Skladiste],'
				SET @SQL = @SQL + ' [Stanje],'
				SET @SQL = @SQL + ' [Rezervirano],'
				SET @SQL = @SQL + ' [Predracun],'
				SET @SQL = @SQL + ' [IDOrganizacijaOd],'
				SET @SQL = @SQL + ' [VPC],'
				SET @SQL = @SQL + ' [MPC]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwArtiklStanjeuSkladistu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwArtiklStanjeVPC_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwArtiklStanjeVPC_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwArtiklStanjeVPC_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwArtiklStanjeVPC view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwArtiklStanjeVPC_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDArtikl],
					[IDOrganizacijaOd],
					[Vrijednost2],
					[MPC],
					[Datum]
				FROM
					[dbo].[vwArtiklStanjeVPC]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwArtiklStanjeVPC_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwArtiklStanjeVPC_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwArtiklStanjeVPC_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwArtiklStanjeVPC view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwArtiklStanjeVPC_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDArtikl]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDArtikl]'
				SET @SQL = @SQL + ', [IDOrganizacijaOd]'
				SET @SQL = @SQL + ', [Vrijednost2]'
				SET @SQL = @SQL + ', [MPC]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ' FROM [dbo].[vwArtiklStanjeVPC]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDArtikl],'
				SET @SQL = @SQL + ' [IDOrganizacijaOd],'
				SET @SQL = @SQL + ' [Vrijednost2],'
				SET @SQL = @SQL + ' [MPC],'
				SET @SQL = @SQL + ' [Datum]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwArtiklStanjeVPC]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwArtiklTrazi_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwArtiklTrazi_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwArtiklTrazi_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwArtiklTrazi view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwArtiklTrazi_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[BarCode],
					[Mjera],
					[Porez],
					[StopaPoreza],
					[ImeKlijenta],
					[Kategorija]
				FROM
					[dbo].[vwArtiklTrazi]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwArtiklTrazi_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwArtiklTrazi_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwArtiklTrazi_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwArtiklTrazi view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwArtiklTrazi_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [BarCode]'
				SET @SQL = @SQL + ', [Mjera]'
				SET @SQL = @SQL + ', [Porez]'
				SET @SQL = @SQL + ', [StopaPoreza]'
				SET @SQL = @SQL + ', [ImeKlijenta]'
				SET @SQL = @SQL + ', [Kategorija]'
				SET @SQL = @SQL + ' FROM [dbo].[vwArtiklTrazi]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [BarCode],'
				SET @SQL = @SQL + ' [Mjera],'
				SET @SQL = @SQL + ' [Porez],'
				SET @SQL = @SQL + ' [StopaPoreza],'
				SET @SQL = @SQL + ' [ImeKlijenta],'
				SET @SQL = @SQL + ' [Kategorija]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwArtiklTrazi]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwBanka_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwBanka_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwBanka_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwBanka view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwBanka_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[Naziv],
					[MB],
					[MinimalniIznos],
					[MaksimalniIznos],
					[MaksimalniBrojRata],
					[Mjesto],
					[PostanskiBroj],
					[SifraOpcine],
					[Prirez],
					[ZiroRacunZaPorezPrirez],
					[TipMjesta],
					[ID],
					[VodeciBrojDepozitneIstitucije]
				FROM
					[dbo].[vwBanka]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwBanka_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwBanka_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwBanka_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwBanka view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwBanka_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Naziv]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [MB]'
				SET @SQL = @SQL + ', [MinimalniIznos]'
				SET @SQL = @SQL + ', [MaksimalniIznos]'
				SET @SQL = @SQL + ', [MaksimalniBrojRata]'
				SET @SQL = @SQL + ', [Mjesto]'
				SET @SQL = @SQL + ', [PostanskiBroj]'
				SET @SQL = @SQL + ', [SifraOpcine]'
				SET @SQL = @SQL + ', [Prirez]'
				SET @SQL = @SQL + ', [ZiroRacunZaPorezPrirez]'
				SET @SQL = @SQL + ', [TipMjesta]'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [VodeciBrojDepozitneIstitucije]'
				SET @SQL = @SQL + ' FROM [dbo].[vwBanka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [MB],'
				SET @SQL = @SQL + ' [MinimalniIznos],'
				SET @SQL = @SQL + ' [MaksimalniIznos],'
				SET @SQL = @SQL + ' [MaksimalniBrojRata],'
				SET @SQL = @SQL + ' [Mjesto],'
				SET @SQL = @SQL + ' [PostanskiBroj],'
				SET @SQL = @SQL + ' [SifraOpcine],'
				SET @SQL = @SQL + ' [Prirez],'
				SET @SQL = @SQL + ' [ZiroRacunZaPorezPrirez],'
				SET @SQL = @SQL + ' [TipMjesta],'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [VodeciBrojDepozitneIstitucije]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwBanka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwBlagajnaIzvjestajSaldo_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwBlagajnaIzvjestajSaldo_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwBlagajnaIzvjestajSaldo_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwBlagajnaIzvjestajSaldo view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwBlagajnaIzvjestajSaldo_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[IDBlagajna],
					[IDUser],
					[IDKnjizenje],
					[Naziv],
					[KontoBlagajna],
					[UlazIzvjestaja],
					[IzlazIzvjestaja],
					[RedniBrojIzvjestaja],
					[BrojStavaka],
					[PocetnoStanje],
					[SaldoIzvjestaja],
					[Saldo],
					[IDProknjizeno]
				FROM
					[fin].[vwBlagajnaIzvjestajSaldo]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwBlagajnaIzvjestajSaldo_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwBlagajnaIzvjestajSaldo_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwBlagajnaIzvjestajSaldo_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwBlagajnaIzvjestajSaldo view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwBlagajnaIzvjestajSaldo_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [IDBlagajna]'
				SET @SQL = @SQL + ', [IDUser]'
				SET @SQL = @SQL + ', [IDKnjizenje]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [KontoBlagajna]'
				SET @SQL = @SQL + ', [UlazIzvjestaja]'
				SET @SQL = @SQL + ', [IzlazIzvjestaja]'
				SET @SQL = @SQL + ', [RedniBrojIzvjestaja]'
				SET @SQL = @SQL + ', [BrojStavaka]'
				SET @SQL = @SQL + ', [PocetnoStanje]'
				SET @SQL = @SQL + ', [SaldoIzvjestaja]'
				SET @SQL = @SQL + ', [Saldo]'
				SET @SQL = @SQL + ', [IDProknjizeno]'
				SET @SQL = @SQL + ' FROM [fin].[vwBlagajnaIzvjestajSaldo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [IDBlagajna],'
				SET @SQL = @SQL + ' [IDUser],'
				SET @SQL = @SQL + ' [IDKnjizenje],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [KontoBlagajna],'
				SET @SQL = @SQL + ' [UlazIzvjestaja],'
				SET @SQL = @SQL + ' [IzlazIzvjestaja],'
				SET @SQL = @SQL + ' [RedniBrojIzvjestaja],'
				SET @SQL = @SQL + ' [BrojStavaka],'
				SET @SQL = @SQL + ' [PocetnoStanje],'
				SET @SQL = @SQL + ' [SaldoIzvjestaja],'
				SET @SQL = @SQL + ' [Saldo],'
				SET @SQL = @SQL + ' [IDProknjizeno]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwBlagajnaIzvjestajSaldo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwBlagajnaSaldo_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwBlagajnaSaldo_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwBlagajnaSaldo_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwBlagajnaSaldo view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwBlagajnaSaldo_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Saldo]
				FROM
					[fin].[vwBlagajnaSaldo]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwBlagajnaSaldo_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwBlagajnaSaldo_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwBlagajnaSaldo_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwBlagajnaSaldo view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwBlagajnaSaldo_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Saldo]'
				SET @SQL = @SQL + ' FROM [fin].[vwBlagajnaSaldo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Saldo]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwBlagajnaSaldo]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwBlagajnaStavka_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwBlagajnaStavka_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwBlagajnaStavka_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwBlagajnaStavka view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwBlagajnaStavka_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDBlagajnaIzvjestaj],
					[DatumDokumenta],
					[Ulaz],
					[Izlaz],
					[DateUICreated],
					[Opis],
					[IDKonto],
					[KontoSifra],
					[Primatelj],
					[IDKlijent],
					[IDOrganizacija],
					[Mjesto],
					[OrgSifra],
					[OrgNaziv],
					[RedniBrojStavke],
					[TipStavke],
					[NazivTipStavke]
				FROM
					[fin].[vwBlagajnaStavka]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwBlagajnaStavka_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwBlagajnaStavka_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwBlagajnaStavka_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwBlagajnaStavka view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwBlagajnaStavka_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDBlagajnaIzvjestaj]'
				SET @SQL = @SQL + ', [DatumDokumenta]'
				SET @SQL = @SQL + ', [Ulaz]'
				SET @SQL = @SQL + ', [Izlaz]'
				SET @SQL = @SQL + ', [DateUICreated]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [IDKonto]'
				SET @SQL = @SQL + ', [KontoSifra]'
				SET @SQL = @SQL + ', [Primatelj]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [IDOrganizacija]'
				SET @SQL = @SQL + ', [Mjesto]'
				SET @SQL = @SQL + ', [OrgSifra]'
				SET @SQL = @SQL + ', [OrgNaziv]'
				SET @SQL = @SQL + ', [RedniBrojStavke]'
				SET @SQL = @SQL + ', [TipStavke]'
				SET @SQL = @SQL + ', [NazivTipStavke]'
				SET @SQL = @SQL + ' FROM [fin].[vwBlagajnaStavka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDBlagajnaIzvjestaj],'
				SET @SQL = @SQL + ' [DatumDokumenta],'
				SET @SQL = @SQL + ' [Ulaz],'
				SET @SQL = @SQL + ' [Izlaz],'
				SET @SQL = @SQL + ' [DateUICreated],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [IDKonto],'
				SET @SQL = @SQL + ' [KontoSifra],'
				SET @SQL = @SQL + ' [Primatelj],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [IDOrganizacija],'
				SET @SQL = @SQL + ' [Mjesto],'
				SET @SQL = @SQL + ' [OrgSifra],'
				SET @SQL = @SQL + ' [OrgNaziv],'
				SET @SQL = @SQL + ' [RedniBrojStavke],'
				SET @SQL = @SQL + ' [TipStavke],'
				SET @SQL = @SQL + ' [NazivTipStavke]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwBlagajnaStavka]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwDefParametriDjelatnika_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwDefParametriDjelatnika_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwDefParametriDjelatnika_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwDefParametriDjelatnika view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwDefParametriDjelatnika_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[Grupa],
					[Naziv],
					[Vrijednost]
				FROM
					[dbo].[vwDefParametriDjelatnika]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwDefParametriDjelatnika_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwDefParametriDjelatnika_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwDefParametriDjelatnika_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwDefParametriDjelatnika view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwDefParametriDjelatnika_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Grupa]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Grupa]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Vrijednost]'
				SET @SQL = @SQL + ' FROM [dbo].[vwDefParametriDjelatnika]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Grupa],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Vrijednost]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwDefParametriDjelatnika]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwDokument_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwDokument_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwDokument_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwDokument view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwDokument_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[Oznaka],
					[Datum],
					[Od],
					[Prema],
					[Primio],
					[Izdao],
					[ImeKlijenta],
					[Transport],
					[Napomena],
					[Napomena2],
					[IDDokumentTip],
					[NabavnaVrijednost],
					[IDDokument],
					[IDStatus],
					[IDOrganizacijaPrema],
					[IDOrganizacijaOd],
					[IDNacinTransporta],
					[IDNacinPlacanja],
					[NacinPlacanja],
					[VezaDokumenta],
					[DatumDo],
					[IDParent],
					[DTSkraceni],
					[RedBr],
					[SifraSkladista]
				FROM
					[dbo].[vwDokument]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwDokument_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwDokument_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwDokument_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwDokument view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwDokument_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Oznaka]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [Od]'
				SET @SQL = @SQL + ', [Prema]'
				SET @SQL = @SQL + ', [Primio]'
				SET @SQL = @SQL + ', [Izdao]'
				SET @SQL = @SQL + ', [ImeKlijenta]'
				SET @SQL = @SQL + ', [Transport]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [Napomena2]'
				SET @SQL = @SQL + ', [IDDokumentTip]'
				SET @SQL = @SQL + ', [NabavnaVrijednost]'
				SET @SQL = @SQL + ', [IDDokument]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ', [IDOrganizacijaPrema]'
				SET @SQL = @SQL + ', [IDOrganizacijaOd]'
				SET @SQL = @SQL + ', [IDNacinTransporta]'
				SET @SQL = @SQL + ', [IDNacinPlacanja]'
				SET @SQL = @SQL + ', [NacinPlacanja]'
				SET @SQL = @SQL + ', [VezaDokumenta]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [IDParent]'
				SET @SQL = @SQL + ', [DTSkraceni]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [SifraSkladista]'
				SET @SQL = @SQL + ' FROM [dbo].[vwDokument]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [Od],'
				SET @SQL = @SQL + ' [Prema],'
				SET @SQL = @SQL + ' [Primio],'
				SET @SQL = @SQL + ' [Izdao],'
				SET @SQL = @SQL + ' [ImeKlijenta],'
				SET @SQL = @SQL + ' [Transport],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [Napomena2],'
				SET @SQL = @SQL + ' [IDDokumentTip],'
				SET @SQL = @SQL + ' [NabavnaVrijednost],'
				SET @SQL = @SQL + ' [IDDokument],'
				SET @SQL = @SQL + ' [IDStatus],'
				SET @SQL = @SQL + ' [IDOrganizacijaPrema],'
				SET @SQL = @SQL + ' [IDOrganizacijaOd],'
				SET @SQL = @SQL + ' [IDNacinTransporta],'
				SET @SQL = @SQL + ' [IDNacinPlacanja],'
				SET @SQL = @SQL + ' [NacinPlacanja],'
				SET @SQL = @SQL + ' [VezaDokumenta],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [IDParent],'
				SET @SQL = @SQL + ' [DTSkraceni],'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [SifraSkladista]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwDokument]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwDozvoleGrupe_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwDozvoleGrupe_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwDozvoleGrupe_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwDozvoleGrupe view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwDozvoleGrupe_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDGrupaDjelatnik],
					[ID],
					[DozvolaZapisa],
					[DozvolaPregled]
				FROM
					[dbo].[vwDozvoleGrupe]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwDozvoleGrupe_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwDozvoleGrupe_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwDozvoleGrupe_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwDozvoleGrupe view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwDozvoleGrupe_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDGrupaDjelatnik]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDGrupaDjelatnik]'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [DozvolaZapisa]'
				SET @SQL = @SQL + ', [DozvolaPregled]'
				SET @SQL = @SQL + ' FROM [dbo].[vwDozvoleGrupe]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDGrupaDjelatnik],'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [DozvolaZapisa],'
				SET @SQL = @SQL + ' [DozvolaPregled]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwDozvoleGrupe]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwDozvoleOrganizacije_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwDozvoleOrganizacije_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwDozvoleOrganizacije_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwDozvoleOrganizacije view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwDozvoleOrganizacije_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DozvolaZapisa],
					[DozvolaPregled]
				FROM
					[dbo].[vwDozvoleOrganizacije]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwDozvoleOrganizacije_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwDozvoleOrganizacije_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwDozvoleOrganizacije_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwDozvoleOrganizacije view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwDozvoleOrganizacije_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [DozvolaZapisa]'
				SET @SQL = @SQL + ', [DozvolaPregled]'
				SET @SQL = @SQL + ' FROM [dbo].[vwDozvoleOrganizacije]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [DozvolaZapisa],'
				SET @SQL = @SQL + ' [DozvolaPregled]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwDozvoleOrganizacije]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwIspis_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwIspis_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwIspis_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwIspis view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwIspis_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IspisID],
					[IspisNaziv],
					[IspisKolonaID],
					[IspisKolonaNaziv],
					[IspisKolonaNaziv2],
					[TipIspisaID],
					[TipIspisaNaziv]
				FROM
					[fin].[vwIspis]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwIspis_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwIspis_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwIspis_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwIspis view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwIspis_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IspisID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IspisID]'
				SET @SQL = @SQL + ', [IspisNaziv]'
				SET @SQL = @SQL + ', [IspisKolonaID]'
				SET @SQL = @SQL + ', [IspisKolonaNaziv]'
				SET @SQL = @SQL + ', [IspisKolonaNaziv2]'
				SET @SQL = @SQL + ', [TipIspisaID]'
				SET @SQL = @SQL + ', [TipIspisaNaziv]'
				SET @SQL = @SQL + ' FROM [fin].[vwIspis]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IspisID],'
				SET @SQL = @SQL + ' [IspisNaziv],'
				SET @SQL = @SQL + ' [IspisKolonaID],'
				SET @SQL = @SQL + ' [IspisKolonaNaziv],'
				SET @SQL = @SQL + ' [IspisKolonaNaziv2],'
				SET @SQL = @SQL + ' [TipIspisaID],'
				SET @SQL = @SQL + ' [TipIspisaNaziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwIspis]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwIzvadak_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwIzvadak_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwIzvadak_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwIzvadak view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwIzvadak_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[BrojDepozitne],
					[DatumIzradeIzvatka],
					[IDKnjizenje]
				FROM
					[dbo].[vwIzvadak]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwIzvadak_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwIzvadak_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwIzvadak_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwIzvadak view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwIzvadak_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [BrojDepozitne]'
				SET @SQL = @SQL + ', [DatumIzradeIzvatka]'
				SET @SQL = @SQL + ', [IDKnjizenje]'
				SET @SQL = @SQL + ' FROM [dbo].[vwIzvadak]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [BrojDepozitne],'
				SET @SQL = @SQL + ' [DatumIzradeIzvatka],'
				SET @SQL = @SQL + ' [IDKnjizenje]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwIzvadak]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwKlijent_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwKlijent_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwKlijent_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwKlijent view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwKlijent_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ImeKlijenta],
					[MB],
					[Adresa],
					[Telefon],
					[Telefon2],
					[Fax],
					[Fax2],
					[WebAdresa],
					[ZiroRacun],
					[ZiroRacun2],
					[ZiroRacun3],
					[Napomena1],
					[Napomena2],
					[Naziv],
					[PostanskiBroj],
					[SifraOpcine],
					[Prirez],
					[ZiroRacunZaPorezPrirez],
					[TipMjesta],
					[KlijentTip],
					[IDTip],
					[ID],
					[Broj],
					[Saldo],
					[SaldoDanas],
					[oib],
					[GarancijaPlacanjaOpis],
					[GarancijaPlacanjaVrijednost],
					[DaniOdgodePlacanja],
					[Komentar]
				FROM
					[dbo].[vwKlijent]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwKlijent_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwKlijent_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwKlijent_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwKlijent view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwKlijent_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ImeKlijenta]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ImeKlijenta]'
				SET @SQL = @SQL + ', [MB]'
				SET @SQL = @SQL + ', [Adresa]'
				SET @SQL = @SQL + ', [Telefon]'
				SET @SQL = @SQL + ', [Telefon2]'
				SET @SQL = @SQL + ', [Fax]'
				SET @SQL = @SQL + ', [Fax2]'
				SET @SQL = @SQL + ', [WebAdresa]'
				SET @SQL = @SQL + ', [ZiroRacun]'
				SET @SQL = @SQL + ', [ZiroRacun2]'
				SET @SQL = @SQL + ', [ZiroRacun3]'
				SET @SQL = @SQL + ', [Napomena1]'
				SET @SQL = @SQL + ', [Napomena2]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [PostanskiBroj]'
				SET @SQL = @SQL + ', [SifraOpcine]'
				SET @SQL = @SQL + ', [Prirez]'
				SET @SQL = @SQL + ', [ZiroRacunZaPorezPrirez]'
				SET @SQL = @SQL + ', [TipMjesta]'
				SET @SQL = @SQL + ', [KlijentTip]'
				SET @SQL = @SQL + ', [IDTip]'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Broj]'
				SET @SQL = @SQL + ', [Saldo]'
				SET @SQL = @SQL + ', [SaldoDanas]'
				SET @SQL = @SQL + ', [oib]'
				SET @SQL = @SQL + ', [GarancijaPlacanjaOpis]'
				SET @SQL = @SQL + ', [GarancijaPlacanjaVrijednost]'
				SET @SQL = @SQL + ', [DaniOdgodePlacanja]'
				SET @SQL = @SQL + ', [Komentar]'
				SET @SQL = @SQL + ' FROM [dbo].[vwKlijent]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ImeKlijenta],'
				SET @SQL = @SQL + ' [MB],'
				SET @SQL = @SQL + ' [Adresa],'
				SET @SQL = @SQL + ' [Telefon],'
				SET @SQL = @SQL + ' [Telefon2],'
				SET @SQL = @SQL + ' [Fax],'
				SET @SQL = @SQL + ' [Fax2],'
				SET @SQL = @SQL + ' [WebAdresa],'
				SET @SQL = @SQL + ' [ZiroRacun],'
				SET @SQL = @SQL + ' [ZiroRacun2],'
				SET @SQL = @SQL + ' [ZiroRacun3],'
				SET @SQL = @SQL + ' [Napomena1],'
				SET @SQL = @SQL + ' [Napomena2],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [PostanskiBroj],'
				SET @SQL = @SQL + ' [SifraOpcine],'
				SET @SQL = @SQL + ' [Prirez],'
				SET @SQL = @SQL + ' [ZiroRacunZaPorezPrirez],'
				SET @SQL = @SQL + ' [TipMjesta],'
				SET @SQL = @SQL + ' [KlijentTip],'
				SET @SQL = @SQL + ' [IDTip],'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Broj],'
				SET @SQL = @SQL + ' [Saldo],'
				SET @SQL = @SQL + ' [SaldoDanas],'
				SET @SQL = @SQL + ' [oib],'
				SET @SQL = @SQL + ' [GarancijaPlacanjaOpis],'
				SET @SQL = @SQL + ' [GarancijaPlacanjaVrijednost],'
				SET @SQL = @SQL + ' [DaniOdgodePlacanja],'
				SET @SQL = @SQL + ' [Komentar]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwKlijent]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwKnjizenje_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwKnjizenje_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwKnjizenje_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwKnjizenje view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwKnjizenje_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKnjizenje],
					[Datum],
					[PrikaznoIme],
					[Naziv],
					[IDOrganizacija],
					[IDStatus],
					[DugUk],
					[PotUk],
					[BrojSt]
				FROM
					[fin].[vwKnjizenje]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwKnjizenje_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwKnjizenje_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwKnjizenje_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwKnjizenje view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwKnjizenje_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDKnjizenje]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDKnjizenje]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [PrikaznoIme]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [IDOrganizacija]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ', [DugUk]'
				SET @SQL = @SQL + ', [PotUk]'
				SET @SQL = @SQL + ', [BrojSt]'
				SET @SQL = @SQL + ' FROM [fin].[vwKnjizenje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDKnjizenje],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [PrikaznoIme],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [IDOrganizacija],'
				SET @SQL = @SQL + ' [IDStatus],'
				SET @SQL = @SQL + ' [DugUk],'
				SET @SQL = @SQL + ' [PotUk],'
				SET @SQL = @SQL + ' [BrojSt]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwKnjizenje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwKnjizenjeIspis_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwKnjizenjeIspis_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwKnjizenjeIspis_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwKnjizenjeIspis view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwKnjizenjeIspis_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKnjiz],
					[IDKnjizStavke],
					[PrikaznoIme],
					[DatumKnjizenja],
					[VK],
					[Nalog],
					[Konto],
					[MT],
					[BrDok],
					[DatumDok],
					[Dug],
					[Pot],
					[Opis],
					[Klijent],
					[PK]
				FROM
					[fin].[vwKnjizenjeIspis]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwKnjizenjeIspis_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwKnjizenjeIspis_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwKnjizenjeIspis_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwKnjizenjeIspis view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwKnjizenjeIspis_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDKnjiz]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDKnjiz]'
				SET @SQL = @SQL + ', [IDKnjizStavke]'
				SET @SQL = @SQL + ', [PrikaznoIme]'
				SET @SQL = @SQL + ', [DatumKnjizenja]'
				SET @SQL = @SQL + ', [VK]'
				SET @SQL = @SQL + ', [Nalog]'
				SET @SQL = @SQL + ', [Konto]'
				SET @SQL = @SQL + ', [MT]'
				SET @SQL = @SQL + ', [BrDok]'
				SET @SQL = @SQL + ', [DatumDok]'
				SET @SQL = @SQL + ', [Dug]'
				SET @SQL = @SQL + ', [Pot]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [Klijent]'
				SET @SQL = @SQL + ', [PK]'
				SET @SQL = @SQL + ' FROM [fin].[vwKnjizenjeIspis]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDKnjiz],'
				SET @SQL = @SQL + ' [IDKnjizStavke],'
				SET @SQL = @SQL + ' [PrikaznoIme],'
				SET @SQL = @SQL + ' [DatumKnjizenja],'
				SET @SQL = @SQL + ' [VK],'
				SET @SQL = @SQL + ' [Nalog],'
				SET @SQL = @SQL + ' [Konto],'
				SET @SQL = @SQL + ' [MT],'
				SET @SQL = @SQL + ' [BrDok],'
				SET @SQL = @SQL + ' [DatumDok],'
				SET @SQL = @SQL + ' [Dug],'
				SET @SQL = @SQL + ' [Pot],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [Klijent],'
				SET @SQL = @SQL + ' [PK]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwKnjizenjeIspis]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwKonto_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwKonto_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwKonto_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwKonto view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwKonto_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Sifra],
					[Naziv],
					[Analiticki],
					[AnalitickiDaNe],
					[IDTip],
					[IDKontoPoreza],
					[DatumOd],
					[DatumDo],
					[TipKontaNaziv]
				FROM
					[fin].[vwKonto]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwKonto_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwKonto_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwKonto_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwKonto view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwKonto_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Sifra]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Analiticki]'
				SET @SQL = @SQL + ', [AnalitickiDaNe]'
				SET @SQL = @SQL + ', [IDTip]'
				SET @SQL = @SQL + ', [IDKontoPoreza]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [TipKontaNaziv]'
				SET @SQL = @SQL + ' FROM [fin].[vwKonto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Sifra],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Analiticki],'
				SET @SQL = @SQL + ' [AnalitickiDaNe],'
				SET @SQL = @SQL + ' [IDTip],'
				SET @SQL = @SQL + ' [IDKontoPoreza],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [TipKontaNaziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwKonto]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwKopiranjeDokumenta_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwKopiranjeDokumenta_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwKopiranjeDokumenta_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwKopiranjeDokumenta view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwKopiranjeDokumenta_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDDokument],
					[RedBr],
					[Oznaka],
					[TipSkraceniNaziv],
					[TipNaziv],
					[IDDokTip],
					[Klijent],
					[MB],
					[DjelatnikIme],
					[DjelatnikUser],
					[SkladisteSifraOd],
					[SkladisteOd],
					[Datum]
				FROM
					[dbo].[vwKopiranjeDokumenta]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwKopiranjeDokumenta_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwKopiranjeDokumenta_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwKopiranjeDokumenta_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwKopiranjeDokumenta view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwKopiranjeDokumenta_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDDokument]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDDokument]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [TipSkraceniNaziv]'
				SET @SQL = @SQL + ', [TipNaziv]'
				SET @SQL = @SQL + ', [IDDokTip]'
				SET @SQL = @SQL + ', [Klijent]'
				SET @SQL = @SQL + ', [MB]'
				SET @SQL = @SQL + ', [DjelatnikIme]'
				SET @SQL = @SQL + ', [DjelatnikUser]'
				SET @SQL = @SQL + ', [SkladisteSifraOd]'
				SET @SQL = @SQL + ', [SkladisteOd]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ' FROM [dbo].[vwKopiranjeDokumenta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDDokument],'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [TipSkraceniNaziv],'
				SET @SQL = @SQL + ' [TipNaziv],'
				SET @SQL = @SQL + ' [IDDokTip],'
				SET @SQL = @SQL + ' [Klijent],'
				SET @SQL = @SQL + ' [MB],'
				SET @SQL = @SQL + ' [DjelatnikIme],'
				SET @SQL = @SQL + ' [DjelatnikUser],'
				SET @SQL = @SQL + ' [SkladisteSifraOd],'
				SET @SQL = @SQL + ' [SkladisteOd],'
				SET @SQL = @SQL + ' [Datum]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwKopiranjeDokumenta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwNc_Po_Dobavljacu_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwNc_Po_Dobavljacu_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwNc_Po_Dobavljacu_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwNc_Po_Dobavljacu view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwNc_Po_Dobavljacu_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDArtikl],
					[IDOrganizacijaOd],
					[NCDobavljac],
					[Datum],
					[ImeKlijenta],
					[IDKlijent]
				FROM
					[dbo].[vwNc_Po_Dobavljacu]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwNc_Po_Dobavljacu_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwNc_Po_Dobavljacu_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwNc_Po_Dobavljacu_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwNc_Po_Dobavljacu view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwNc_Po_Dobavljacu_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDArtikl]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDArtikl]'
				SET @SQL = @SQL + ', [IDOrganizacijaOd]'
				SET @SQL = @SQL + ', [NCDobavljac]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [ImeKlijenta]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ' FROM [dbo].[vwNc_Po_Dobavljacu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDArtikl],'
				SET @SQL = @SQL + ' [IDOrganizacijaOd],'
				SET @SQL = @SQL + ' [NCDobavljac],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [ImeKlijenta],'
				SET @SQL = @SQL + ' [IDKlijent]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwNc_Po_Dobavljacu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunDefaultVrijednosti_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunDefaultVrijednosti_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunDefaultVrijednosti_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunDefaultVrijednosti view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunDefaultVrijednosti_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[VrstaUplateRSM],
					[MinimalniOsobniOdbitak],
					[MaksimalniIznosPorezneOlaksice],
					[IdentifikatorIDObrasca],
					[DoprinosPoDanuBoravkaUInozemstvu],
					[DoprinosNezgoda],
					[DoprinosZdravstveno],
					[DoprinosZaposljavanjeSInvaliditetom],
					[RSMVrstaObveznika],
					[DoprinosZaposljavanje],
					[MIO1aPostotak],
					[MIO1bPostotak],
					[MIO2Postotak],
					[NajvisaMjOsnovica]
				FROM
					[pla].[vwObracunDefaultVrijednosti]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunDefaultVrijednosti_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunDefaultVrijednosti_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunDefaultVrijednosti_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunDefaultVrijednosti view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunDefaultVrijednosti_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[VrstaUplateRSM]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [VrstaUplateRSM]'
				SET @SQL = @SQL + ', [MinimalniOsobniOdbitak]'
				SET @SQL = @SQL + ', [MaksimalniIznosPorezneOlaksice]'
				SET @SQL = @SQL + ', [IdentifikatorIDObrasca]'
				SET @SQL = @SQL + ', [DoprinosPoDanuBoravkaUInozemstvu]'
				SET @SQL = @SQL + ', [DoprinosNezgoda]'
				SET @SQL = @SQL + ', [DoprinosZdravstveno]'
				SET @SQL = @SQL + ', [DoprinosZaposljavanjeSInvaliditetom]'
				SET @SQL = @SQL + ', [RSMVrstaObveznika]'
				SET @SQL = @SQL + ', [DoprinosZaposljavanje]'
				SET @SQL = @SQL + ', [MIO1aPostotak]'
				SET @SQL = @SQL + ', [MIO1bPostotak]'
				SET @SQL = @SQL + ', [MIO2Postotak]'
				SET @SQL = @SQL + ', [NajvisaMjOsnovica]'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunDefaultVrijednosti]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [VrstaUplateRSM],'
				SET @SQL = @SQL + ' [MinimalniOsobniOdbitak],'
				SET @SQL = @SQL + ' [MaksimalniIznosPorezneOlaksice],'
				SET @SQL = @SQL + ' [IdentifikatorIDObrasca],'
				SET @SQL = @SQL + ' [DoprinosPoDanuBoravkaUInozemstvu],'
				SET @SQL = @SQL + ' [DoprinosNezgoda],'
				SET @SQL = @SQL + ' [DoprinosZdravstveno],'
				SET @SQL = @SQL + ' [DoprinosZaposljavanjeSInvaliditetom],'
				SET @SQL = @SQL + ' [RSMVrstaObveznika],'
				SET @SQL = @SQL + ' [DoprinosZaposljavanje],'
				SET @SQL = @SQL + ' [MIO1aPostotak],'
				SET @SQL = @SQL + ' [MIO1bPostotak],'
				SET @SQL = @SQL + ' [MIO2Postotak],'
				SET @SQL = @SQL + ' [NajvisaMjOsnovica]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunDefaultVrijednosti]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwObracunKamata_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwObracunKamata_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwObracunKamata_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunKamata view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwObracunKamata_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKnjizStavke],
					[Konto],
					[MTSifra],
					[MT],
					[IDKlijent],
					[MB],
					[ImeKlijenta],
					[LokacijeKlijenta],
					[Adresa],
					[Faktura],
					[DatumFakture],
					[Iznos],
					[RazdobljeOd],
					[RazdobljeDo],
					[Dana],
					[Stopa],
					[IznosKamate],
					[DatumZadnjeUplate],
					[DatumOd],
					[DatumDo]
				FROM
					[fin].[vwObracunKamata]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwObracunKamata_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwObracunKamata_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwObracunKamata_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunKamata view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwObracunKamata_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDKnjizStavke]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDKnjizStavke]'
				SET @SQL = @SQL + ', [Konto]'
				SET @SQL = @SQL + ', [MTSifra]'
				SET @SQL = @SQL + ', [MT]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [MB]'
				SET @SQL = @SQL + ', [ImeKlijenta]'
				SET @SQL = @SQL + ', [LokacijeKlijenta]'
				SET @SQL = @SQL + ', [Adresa]'
				SET @SQL = @SQL + ', [Faktura]'
				SET @SQL = @SQL + ', [DatumFakture]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [RazdobljeOd]'
				SET @SQL = @SQL + ', [RazdobljeDo]'
				SET @SQL = @SQL + ', [Dana]'
				SET @SQL = @SQL + ', [Stopa]'
				SET @SQL = @SQL + ', [IznosKamate]'
				SET @SQL = @SQL + ', [DatumZadnjeUplate]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ' FROM [fin].[vwObracunKamata]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDKnjizStavke],'
				SET @SQL = @SQL + ' [Konto],'
				SET @SQL = @SQL + ' [MTSifra],'
				SET @SQL = @SQL + ' [MT],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [MB],'
				SET @SQL = @SQL + ' [ImeKlijenta],'
				SET @SQL = @SQL + ' [LokacijeKlijenta],'
				SET @SQL = @SQL + ' [Adresa],'
				SET @SQL = @SQL + ' [Faktura],'
				SET @SQL = @SQL + ' [DatumFakture],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [RazdobljeOd],'
				SET @SQL = @SQL + ' [RazdobljeDo],'
				SET @SQL = @SQL + ' [Dana],'
				SET @SQL = @SQL + ' [Stopa],'
				SET @SQL = @SQL + ' [IznosKamate],'
				SET @SQL = @SQL + ' [DatumZadnjeUplate],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwObracunKamata]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwObracunKamataTrazi_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwObracunKamataTrazi_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwObracunKamataTrazi_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunKamataTrazi view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwObracunKamataTrazi_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[RedBr],
					[DatumObracuna],
					[MB],
					[Poslpartner],
					[MTnaziv],
					[Oznaka],
					[Djelatnik],
					[IDStatus],
					[Sifraskladista],
					[IDObracunKamata],
					[IDKlijent],
					[IDOrganizacija]
				FROM
					[fin].[vwObracunKamataTrazi]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwObracunKamataTrazi_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwObracunKamataTrazi_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwObracunKamataTrazi_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunKamataTrazi view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwObracunKamataTrazi_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[RedBr]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [DatumObracuna]'
				SET @SQL = @SQL + ', [MB]'
				SET @SQL = @SQL + ', [Poslpartner]'
				SET @SQL = @SQL + ', [MTnaziv]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [Djelatnik]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ', [Sifraskladista]'
				SET @SQL = @SQL + ', [IDObracunKamata]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [IDOrganizacija]'
				SET @SQL = @SQL + ' FROM [fin].[vwObracunKamataTrazi]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [DatumObracuna],'
				SET @SQL = @SQL + ' [MB],'
				SET @SQL = @SQL + ' [Poslpartner],'
				SET @SQL = @SQL + ' [MTnaziv],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [Djelatnik],'
				SET @SQL = @SQL + ' [IDStatus],'
				SET @SQL = @SQL + ' [Sifraskladista],'
				SET @SQL = @SQL + ' [IDObracunKamata],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [IDOrganizacija]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwObracunKamataTrazi]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunSpecifikacijaPoBankama_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunSpecifikacijaPoBankama_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunSpecifikacijaPoBankama_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunSpecifikacijaPoBankama view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunSpecifikacijaPoBankama_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDObracun],
					[NazivBanke],
					[BrojRacunaBanke],
					[ModelZaIsplatuBanci],
					[PozivZaIsplatuBanci],
					[PrezimeIme],
					[BrojRacunaOsobe],
					[ZaIsplatu],
					[DatumIsplate]
				FROM
					[pla].[vwObracunSpecifikacijaPoBankama]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunSpecifikacijaPoBankama_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunSpecifikacijaPoBankama_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunSpecifikacijaPoBankama_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunSpecifikacijaPoBankama view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunSpecifikacijaPoBankama_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDObracun]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDObracun]'
				SET @SQL = @SQL + ', [NazivBanke]'
				SET @SQL = @SQL + ', [BrojRacunaBanke]'
				SET @SQL = @SQL + ', [ModelZaIsplatuBanci]'
				SET @SQL = @SQL + ', [PozivZaIsplatuBanci]'
				SET @SQL = @SQL + ', [PrezimeIme]'
				SET @SQL = @SQL + ', [BrojRacunaOsobe]'
				SET @SQL = @SQL + ', [ZaIsplatu]'
				SET @SQL = @SQL + ', [DatumIsplate]'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunSpecifikacijaPoBankama]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDObracun],'
				SET @SQL = @SQL + ' [NazivBanke],'
				SET @SQL = @SQL + ' [BrojRacunaBanke],'
				SET @SQL = @SQL + ' [ModelZaIsplatuBanci],'
				SET @SQL = @SQL + ' [PozivZaIsplatuBanci],'
				SET @SQL = @SQL + ' [PrezimeIme],'
				SET @SQL = @SQL + ' [BrojRacunaOsobe],'
				SET @SQL = @SQL + ' [ZaIsplatu],'
				SET @SQL = @SQL + ' [DatumIsplate]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunSpecifikacijaPoBankama]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunTemeljnicaZaKnjizenje_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunTemeljnicaZaKnjizenje_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunTemeljnicaZaKnjizenje_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunTemeljnicaZaKnjizenje view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunTemeljnicaZaKnjizenje_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[Konto],
					[ObracunMjesec],
					[ObracunGodina],
					[IDObracun],
					[DatumDo],
					[Opis],
					[RedniBrojUGodini],
					[Dug],
					[Pot],
					[VrDok]
				FROM
					[pla].[vwObracunTemeljnicaZaKnjizenje]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunTemeljnicaZaKnjizenje_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunTemeljnicaZaKnjizenje_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunTemeljnicaZaKnjizenje_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunTemeljnicaZaKnjizenje view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunTemeljnicaZaKnjizenje_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Konto]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Konto]'
				SET @SQL = @SQL + ', [ObracunMjesec]'
				SET @SQL = @SQL + ', [ObracunGodina]'
				SET @SQL = @SQL + ', [IDObracun]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [RedniBrojUGodini]'
				SET @SQL = @SQL + ', [Dug]'
				SET @SQL = @SQL + ', [Pot]'
				SET @SQL = @SQL + ', [VrDok]'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunTemeljnicaZaKnjizenje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Konto],'
				SET @SQL = @SQL + ' [ObracunMjesec],'
				SET @SQL = @SQL + ' [ObracunGodina],'
				SET @SQL = @SQL + ' [IDObracun],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [RedniBrojUGodini],'
				SET @SQL = @SQL + ' [Dug],'
				SET @SQL = @SQL + ' [Pot],'
				SET @SQL = @SQL + ' [VrDok]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunTemeljnicaZaKnjizenje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunTrazi_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunTrazi_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunTrazi_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunTrazi view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunTrazi_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[DatumOd],
					[DatumDo],
					[VrstaUplateRSMSifra],
					[VrstaUplateRSMNaziv],
					[IdentifikatorIDObrascaSifra],
					[IdentifikatorIDObrasacNaziv],
					[RedniBrojUGodini],
					[FondSati],
					[BrutoOsnovica],
					[BrOsoba],
					[SumBruto],
					[SumNeto],
					[SumBruto2],
					[AvgBruto],
					[AvgNeto],
					[AvgBruto2],
					[Status]
				FROM
					[pla].[vwObracunTrazi]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunTrazi_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunTrazi_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunTrazi_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunTrazi view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunTrazi_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [VrstaUplateRSMSifra]'
				SET @SQL = @SQL + ', [VrstaUplateRSMNaziv]'
				SET @SQL = @SQL + ', [IdentifikatorIDObrascaSifra]'
				SET @SQL = @SQL + ', [IdentifikatorIDObrasacNaziv]'
				SET @SQL = @SQL + ', [RedniBrojUGodini]'
				SET @SQL = @SQL + ', [FondSati]'
				SET @SQL = @SQL + ', [BrutoOsnovica]'
				SET @SQL = @SQL + ', [BrOsoba]'
				SET @SQL = @SQL + ', [SumBruto]'
				SET @SQL = @SQL + ', [SumNeto]'
				SET @SQL = @SQL + ', [SumBruto2]'
				SET @SQL = @SQL + ', [AvgBruto]'
				SET @SQL = @SQL + ', [AvgNeto]'
				SET @SQL = @SQL + ', [AvgBruto2]'
				SET @SQL = @SQL + ', [Status]'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunTrazi]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [VrstaUplateRSMSifra],'
				SET @SQL = @SQL + ' [VrstaUplateRSMNaziv],'
				SET @SQL = @SQL + ' [IdentifikatorIDObrascaSifra],'
				SET @SQL = @SQL + ' [IdentifikatorIDObrasacNaziv],'
				SET @SQL = @SQL + ' [RedniBrojUGodini],'
				SET @SQL = @SQL + ' [FondSati],'
				SET @SQL = @SQL + ' [BrutoOsnovica],'
				SET @SQL = @SQL + ' [BrOsoba],'
				SET @SQL = @SQL + ' [SumBruto],'
				SET @SQL = @SQL + ' [SumNeto],'
				SET @SQL = @SQL + ' [SumBruto2],'
				SET @SQL = @SQL + ' [AvgBruto],'
				SET @SQL = @SQL + ' [AvgNeto],'
				SET @SQL = @SQL + ' [AvgBruto2],'
				SET @SQL = @SQL + ' [Status]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunTrazi]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunVirmani_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunVirmani_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunVirmani_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunVirmani view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunVirmani_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[NalogodavateljNaziv],
					[NalogodavateljSjediste],
					[NalogodavateljRacun],
					[NalogodavateljModel],
					[NalogodavateljPoziv],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[OpisPlacanja],
					[ZiroRacunZaPorezPrirez],
					[Iznos],
					[Model],
					[PozivNaBroj],
					[IDObracun],
					[DatumIsplate],
					[ZadModel],
					[ZadPoziv]
				FROM
					[pla].[vwObracunVirmani]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunVirmani_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunVirmani_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunVirmani_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunVirmani view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunVirmani_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[NalogodavateljNaziv]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [NalogodavateljNaziv]'
				SET @SQL = @SQL + ', [NalogodavateljSjediste]'
				SET @SQL = @SQL + ', [NalogodavateljRacun]'
				SET @SQL = @SQL + ', [NalogodavateljModel]'
				SET @SQL = @SQL + ', [NalogodavateljPoziv]'
				SET @SQL = @SQL + ', [PrimateljNaziv]'
				SET @SQL = @SQL + ', [PrimateljSjediste]'
				SET @SQL = @SQL + ', [OpisPlacanja]'
				SET @SQL = @SQL + ', [ZiroRacunZaPorezPrirez]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [Model]'
				SET @SQL = @SQL + ', [PozivNaBroj]'
				SET @SQL = @SQL + ', [IDObracun]'
				SET @SQL = @SQL + ', [DatumIsplate]'
				SET @SQL = @SQL + ', [ZadModel]'
				SET @SQL = @SQL + ', [ZadPoziv]'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunVirmani]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [NalogodavateljNaziv],'
				SET @SQL = @SQL + ' [NalogodavateljSjediste],'
				SET @SQL = @SQL + ' [NalogodavateljRacun],'
				SET @SQL = @SQL + ' [NalogodavateljModel],'
				SET @SQL = @SQL + ' [NalogodavateljPoziv],'
				SET @SQL = @SQL + ' [PrimateljNaziv],'
				SET @SQL = @SQL + ' [PrimateljSjediste],'
				SET @SQL = @SQL + ' [OpisPlacanja],'
				SET @SQL = @SQL + ' [ZiroRacunZaPorezPrirez],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [Model],'
				SET @SQL = @SQL + ' [PozivNaBroj],'
				SET @SQL = @SQL + ' [IDObracun],'
				SET @SQL = @SQL + ' [DatumIsplate],'
				SET @SQL = @SQL + ' [ZadModel],'
				SET @SQL = @SQL + ' [ZadPoziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunVirmani]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunZaID_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunZaID_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunZaID_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunZaID view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunZaID_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDObracun],
					[Naziv],
					[Sjediste],
					[IPPU],
					[IBObveznika],
					[IdentifikatorIDNaziv],
					[IdentifikatorIDSifra],
					[RSMVrstaObracunaOpis],
					[RSMVrstaObracunaSifra],
					[RSMVrstaObveznikaOpis],
					[RSMVrstaObveznikaSifra],
					[UkBrojStranica],
					[UkBrojOsoba],
					[IsplaceniPrimici],
					[OsnovicaZaIzracundoprinosa],
					[MIO1],
					[MIO2],
					[Dohodak],
					[OsobniOdbici],
					[PorOsnovica],
					[ObracunatPorezIPrirez],
					[ObracunatPorez],
					[ObracunatPrirez],
					[BrojRadnika],
					[MIO1Osnovno],
					[MIO1Povecano],
					[MIO2Osnovno],
					[MIO2Povecano],
					[Zdrav],
					[ZastitaNaRadu],
					[Zaposljavanje],
					[Invaliditet],
					[ZdrInozemstvo],
					[UkNetoPredPosPorez],
					[UkNetoIsplata],
					[UkPosPorez],
					[DatumIsplate],
					[DatumOd],
					[DatumDo],
					[RedniBrojUGodini],
					[ObracunMjesec],
					[ObracunGodina],
					[IsplataMjesec],
					[IsplataGodina],
					[RSMSHA],
					[BrojOsobaSPosPorezom],
					[PorOsnovicaPosPorez]
				FROM
					[pla].[vwObracunZaID]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunZaID_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunZaID_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunZaID_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunZaID view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunZaID_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDObracun]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDObracun]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Sjediste]'
				SET @SQL = @SQL + ', [IPPU]'
				SET @SQL = @SQL + ', [IBObveznika]'
				SET @SQL = @SQL + ', [IdentifikatorIDNaziv]'
				SET @SQL = @SQL + ', [IdentifikatorIDSifra]'
				SET @SQL = @SQL + ', [RSMVrstaObracunaOpis]'
				SET @SQL = @SQL + ', [RSMVrstaObracunaSifra]'
				SET @SQL = @SQL + ', [RSMVrstaObveznikaOpis]'
				SET @SQL = @SQL + ', [RSMVrstaObveznikaSifra]'
				SET @SQL = @SQL + ', [UkBrojStranica]'
				SET @SQL = @SQL + ', [UkBrojOsoba]'
				SET @SQL = @SQL + ', [IsplaceniPrimici]'
				SET @SQL = @SQL + ', [OsnovicaZaIzracundoprinosa]'
				SET @SQL = @SQL + ', [MIO1]'
				SET @SQL = @SQL + ', [MIO2]'
				SET @SQL = @SQL + ', [Dohodak]'
				SET @SQL = @SQL + ', [OsobniOdbici]'
				SET @SQL = @SQL + ', [PorOsnovica]'
				SET @SQL = @SQL + ', [ObracunatPorezIPrirez]'
				SET @SQL = @SQL + ', [ObracunatPorez]'
				SET @SQL = @SQL + ', [ObracunatPrirez]'
				SET @SQL = @SQL + ', [BrojRadnika]'
				SET @SQL = @SQL + ', [MIO1Osnovno]'
				SET @SQL = @SQL + ', [MIO1Povecano]'
				SET @SQL = @SQL + ', [MIO2Osnovno]'
				SET @SQL = @SQL + ', [MIO2Povecano]'
				SET @SQL = @SQL + ', [Zdrav]'
				SET @SQL = @SQL + ', [ZastitaNaRadu]'
				SET @SQL = @SQL + ', [Zaposljavanje]'
				SET @SQL = @SQL + ', [Invaliditet]'
				SET @SQL = @SQL + ', [ZdrInozemstvo]'
				SET @SQL = @SQL + ', [UkNetoPredPosPorez]'
				SET @SQL = @SQL + ', [UkNetoIsplata]'
				SET @SQL = @SQL + ', [UkPosPorez]'
				SET @SQL = @SQL + ', [DatumIsplate]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [RedniBrojUGodini]'
				SET @SQL = @SQL + ', [ObracunMjesec]'
				SET @SQL = @SQL + ', [ObracunGodina]'
				SET @SQL = @SQL + ', [IsplataMjesec]'
				SET @SQL = @SQL + ', [IsplataGodina]'
				SET @SQL = @SQL + ', [RSMSHA]'
				SET @SQL = @SQL + ', [BrojOsobaSPosPorezom]'
				SET @SQL = @SQL + ', [PorOsnovicaPosPorez]'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunZaID]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDObracun],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Sjediste],'
				SET @SQL = @SQL + ' [IPPU],'
				SET @SQL = @SQL + ' [IBObveznika],'
				SET @SQL = @SQL + ' [IdentifikatorIDNaziv],'
				SET @SQL = @SQL + ' [IdentifikatorIDSifra],'
				SET @SQL = @SQL + ' [RSMVrstaObracunaOpis],'
				SET @SQL = @SQL + ' [RSMVrstaObracunaSifra],'
				SET @SQL = @SQL + ' [RSMVrstaObveznikaOpis],'
				SET @SQL = @SQL + ' [RSMVrstaObveznikaSifra],'
				SET @SQL = @SQL + ' [UkBrojStranica],'
				SET @SQL = @SQL + ' [UkBrojOsoba],'
				SET @SQL = @SQL + ' [IsplaceniPrimici],'
				SET @SQL = @SQL + ' [OsnovicaZaIzracundoprinosa],'
				SET @SQL = @SQL + ' [MIO1],'
				SET @SQL = @SQL + ' [MIO2],'
				SET @SQL = @SQL + ' [Dohodak],'
				SET @SQL = @SQL + ' [OsobniOdbici],'
				SET @SQL = @SQL + ' [PorOsnovica],'
				SET @SQL = @SQL + ' [ObracunatPorezIPrirez],'
				SET @SQL = @SQL + ' [ObracunatPorez],'
				SET @SQL = @SQL + ' [ObracunatPrirez],'
				SET @SQL = @SQL + ' [BrojRadnika],'
				SET @SQL = @SQL + ' [MIO1Osnovno],'
				SET @SQL = @SQL + ' [MIO1Povecano],'
				SET @SQL = @SQL + ' [MIO2Osnovno],'
				SET @SQL = @SQL + ' [MIO2Povecano],'
				SET @SQL = @SQL + ' [Zdrav],'
				SET @SQL = @SQL + ' [ZastitaNaRadu],'
				SET @SQL = @SQL + ' [Zaposljavanje],'
				SET @SQL = @SQL + ' [Invaliditet],'
				SET @SQL = @SQL + ' [ZdrInozemstvo],'
				SET @SQL = @SQL + ' [UkNetoPredPosPorez],'
				SET @SQL = @SQL + ' [UkNetoIsplata],'
				SET @SQL = @SQL + ' [UkPosPorez],'
				SET @SQL = @SQL + ' [DatumIsplate],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [RedniBrojUGodini],'
				SET @SQL = @SQL + ' [ObracunMjesec],'
				SET @SQL = @SQL + ' [ObracunGodina],'
				SET @SQL = @SQL + ' [IsplataMjesec],'
				SET @SQL = @SQL + ' [IsplataGodina],'
				SET @SQL = @SQL + ' [RSMSHA],'
				SET @SQL = @SQL + ' [BrojOsobaSPosPorezom],'
				SET @SQL = @SQL + ' [PorOsnovicaPosPorez]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunZaID]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunZaIDPoObrascu_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunZaIDPoObrascu_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunZaIDPoObrascu_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunZaIDPoObrascu view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunZaIDPoObrascu_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDObracun],
					[Naziv],
					[Sjediste],
					[IPPU],
					[IBObveznika],
					[IdentifikatorIDNaziv],
					[IdentifikatorIDSifra],
					[RSMVrstaObracunaOpis],
					[RSMVrstaObracunaSifra],
					[RSMVrstaObveznikaOpis],
					[RSMVrstaObveznikaSifra],
					[UkBrojStranica],
					[UkBrojOsoba],
					[IsplaceniPrimici],
					[OsnovicaZaIzracundoprinosa],
					[MIO1],
					[MIO2],
					[Dohodak],
					[OsobniOdbici],
					[PorOsnovica],
					[ObracunatPorezIPrirez],
					[ObracunatPorez],
					[ObracunatPrirez],
					[BrojRadnika],
					[MIO1Osnovno],
					[MIO1Povecano],
					[MIO2Osnovno],
					[MIO2Povecano],
					[Zdrav],
					[ZastitaNaRadu],
					[Zaposljavanje],
					[Invaliditet],
					[ZdrInozemstvo],
					[UkNetoPredPosPorez],
					[UkNetoIsplata],
					[UkPosPorez],
					[DatumIsplate],
					[DatumOd],
					[DatumDo],
					[RedniBrojUGodini],
					[ObracunMjesec],
					[ObracunGodina],
					[IsplataMjesec],
					[IsplataGodina],
					[RSMSHA],
					[BrojOsobaSPosPorezom],
					[PorOsnovicaPosPorez],
					[ObrazacIndentifikator]
				FROM
					[pla].[vwObracunZaIDPoObrascu]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunZaIDPoObrascu_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunZaIDPoObrascu_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunZaIDPoObrascu_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunZaIDPoObrascu view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunZaIDPoObrascu_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDObracun]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDObracun]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [Sjediste]'
				SET @SQL = @SQL + ', [IPPU]'
				SET @SQL = @SQL + ', [IBObveznika]'
				SET @SQL = @SQL + ', [IdentifikatorIDNaziv]'
				SET @SQL = @SQL + ', [IdentifikatorIDSifra]'
				SET @SQL = @SQL + ', [RSMVrstaObracunaOpis]'
				SET @SQL = @SQL + ', [RSMVrstaObracunaSifra]'
				SET @SQL = @SQL + ', [RSMVrstaObveznikaOpis]'
				SET @SQL = @SQL + ', [RSMVrstaObveznikaSifra]'
				SET @SQL = @SQL + ', [UkBrojStranica]'
				SET @SQL = @SQL + ', [UkBrojOsoba]'
				SET @SQL = @SQL + ', [IsplaceniPrimici]'
				SET @SQL = @SQL + ', [OsnovicaZaIzracundoprinosa]'
				SET @SQL = @SQL + ', [MIO1]'
				SET @SQL = @SQL + ', [MIO2]'
				SET @SQL = @SQL + ', [Dohodak]'
				SET @SQL = @SQL + ', [OsobniOdbici]'
				SET @SQL = @SQL + ', [PorOsnovica]'
				SET @SQL = @SQL + ', [ObracunatPorezIPrirez]'
				SET @SQL = @SQL + ', [ObracunatPorez]'
				SET @SQL = @SQL + ', [ObracunatPrirez]'
				SET @SQL = @SQL + ', [BrojRadnika]'
				SET @SQL = @SQL + ', [MIO1Osnovno]'
				SET @SQL = @SQL + ', [MIO1Povecano]'
				SET @SQL = @SQL + ', [MIO2Osnovno]'
				SET @SQL = @SQL + ', [MIO2Povecano]'
				SET @SQL = @SQL + ', [Zdrav]'
				SET @SQL = @SQL + ', [ZastitaNaRadu]'
				SET @SQL = @SQL + ', [Zaposljavanje]'
				SET @SQL = @SQL + ', [Invaliditet]'
				SET @SQL = @SQL + ', [ZdrInozemstvo]'
				SET @SQL = @SQL + ', [UkNetoPredPosPorez]'
				SET @SQL = @SQL + ', [UkNetoIsplata]'
				SET @SQL = @SQL + ', [UkPosPorez]'
				SET @SQL = @SQL + ', [DatumIsplate]'
				SET @SQL = @SQL + ', [DatumOd]'
				SET @SQL = @SQL + ', [DatumDo]'
				SET @SQL = @SQL + ', [RedniBrojUGodini]'
				SET @SQL = @SQL + ', [ObracunMjesec]'
				SET @SQL = @SQL + ', [ObracunGodina]'
				SET @SQL = @SQL + ', [IsplataMjesec]'
				SET @SQL = @SQL + ', [IsplataGodina]'
				SET @SQL = @SQL + ', [RSMSHA]'
				SET @SQL = @SQL + ', [BrojOsobaSPosPorezom]'
				SET @SQL = @SQL + ', [PorOsnovicaPosPorez]'
				SET @SQL = @SQL + ', [ObrazacIndentifikator]'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunZaIDPoObrascu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDObracun],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [Sjediste],'
				SET @SQL = @SQL + ' [IPPU],'
				SET @SQL = @SQL + ' [IBObveznika],'
				SET @SQL = @SQL + ' [IdentifikatorIDNaziv],'
				SET @SQL = @SQL + ' [IdentifikatorIDSifra],'
				SET @SQL = @SQL + ' [RSMVrstaObracunaOpis],'
				SET @SQL = @SQL + ' [RSMVrstaObracunaSifra],'
				SET @SQL = @SQL + ' [RSMVrstaObveznikaOpis],'
				SET @SQL = @SQL + ' [RSMVrstaObveznikaSifra],'
				SET @SQL = @SQL + ' [UkBrojStranica],'
				SET @SQL = @SQL + ' [UkBrojOsoba],'
				SET @SQL = @SQL + ' [IsplaceniPrimici],'
				SET @SQL = @SQL + ' [OsnovicaZaIzracundoprinosa],'
				SET @SQL = @SQL + ' [MIO1],'
				SET @SQL = @SQL + ' [MIO2],'
				SET @SQL = @SQL + ' [Dohodak],'
				SET @SQL = @SQL + ' [OsobniOdbici],'
				SET @SQL = @SQL + ' [PorOsnovica],'
				SET @SQL = @SQL + ' [ObracunatPorezIPrirez],'
				SET @SQL = @SQL + ' [ObracunatPorez],'
				SET @SQL = @SQL + ' [ObracunatPrirez],'
				SET @SQL = @SQL + ' [BrojRadnika],'
				SET @SQL = @SQL + ' [MIO1Osnovno],'
				SET @SQL = @SQL + ' [MIO1Povecano],'
				SET @SQL = @SQL + ' [MIO2Osnovno],'
				SET @SQL = @SQL + ' [MIO2Povecano],'
				SET @SQL = @SQL + ' [Zdrav],'
				SET @SQL = @SQL + ' [ZastitaNaRadu],'
				SET @SQL = @SQL + ' [Zaposljavanje],'
				SET @SQL = @SQL + ' [Invaliditet],'
				SET @SQL = @SQL + ' [ZdrInozemstvo],'
				SET @SQL = @SQL + ' [UkNetoPredPosPorez],'
				SET @SQL = @SQL + ' [UkNetoIsplata],'
				SET @SQL = @SQL + ' [UkPosPorez],'
				SET @SQL = @SQL + ' [DatumIsplate],'
				SET @SQL = @SQL + ' [DatumOd],'
				SET @SQL = @SQL + ' [DatumDo],'
				SET @SQL = @SQL + ' [RedniBrojUGodini],'
				SET @SQL = @SQL + ' [ObracunMjesec],'
				SET @SQL = @SQL + ' [ObracunGodina],'
				SET @SQL = @SQL + ' [IsplataMjesec],'
				SET @SQL = @SQL + ' [IsplataGodina],'
				SET @SQL = @SQL + ' [RSMSHA],'
				SET @SQL = @SQL + ' [BrojOsobaSPosPorezom],'
				SET @SQL = @SQL + ' [PorOsnovicaPosPorez],'
				SET @SQL = @SQL + ' [ObrazacIndentifikator]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunZaIDPoObrascu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunZaIDPorezPrirez_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunZaIDPorezPrirez_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunZaIDPorezPrirez_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunZaIDPorezPrirez view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunZaIDPorezPrirez_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDObracun],
					[Mjesto],
					[SifraOpcine],
					[PorezIznos],
					[PrirezIznos],
					[Ukupno]
				FROM
					[pla].[vwObracunZaIDPorezPrirez]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunZaIDPorezPrirez_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunZaIDPorezPrirez_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunZaIDPorezPrirez_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunZaIDPorezPrirez view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunZaIDPorezPrirez_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDObracun]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDObracun]'
				SET @SQL = @SQL + ', [Mjesto]'
				SET @SQL = @SQL + ', [SifraOpcine]'
				SET @SQL = @SQL + ', [PorezIznos]'
				SET @SQL = @SQL + ', [PrirezIznos]'
				SET @SQL = @SQL + ', [Ukupno]'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunZaIDPorezPrirez]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDObracun],'
				SET @SQL = @SQL + ' [Mjesto],'
				SET @SQL = @SQL + ' [SifraOpcine],'
				SET @SQL = @SQL + ' [PorezIznos],'
				SET @SQL = @SQL + ' [PrirezIznos],'
				SET @SQL = @SQL + ' [Ukupno]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunZaIDPorezPrirez]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunZaIDPorezPrirezPoObrascu_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunZaIDPorezPrirezPoObrascu_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunZaIDPorezPrirezPoObrascu_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunZaIDPorezPrirezPoObrascu view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunZaIDPorezPrirezPoObrascu_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDObracun],
					[Mjesto],
					[SifraOpcine],
					[PorezIznos],
					[PrirezIznos],
					[Ukupno],
					[ObrazacIndentifikator]
				FROM
					[pla].[vwObracunZaIDPorezPrirezPoObrascu]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunZaIDPorezPrirezPoObrascu_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunZaIDPorezPrirezPoObrascu_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunZaIDPorezPrirezPoObrascu_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunZaIDPorezPrirezPoObrascu view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunZaIDPorezPrirezPoObrascu_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDObracun]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDObracun]'
				SET @SQL = @SQL + ', [Mjesto]'
				SET @SQL = @SQL + ', [SifraOpcine]'
				SET @SQL = @SQL + ', [PorezIznos]'
				SET @SQL = @SQL + ', [PrirezIznos]'
				SET @SQL = @SQL + ', [Ukupno]'
				SET @SQL = @SQL + ', [ObrazacIndentifikator]'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunZaIDPorezPrirezPoObrascu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDObracun],'
				SET @SQL = @SQL + ' [Mjesto],'
				SET @SQL = @SQL + ' [SifraOpcine],'
				SET @SQL = @SQL + ' [PorezIznos],'
				SET @SQL = @SQL + ' [PrirezIznos],'
				SET @SQL = @SQL + ' [Ukupno],'
				SET @SQL = @SQL + ' [ObrazacIndentifikator]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunZaIDPorezPrirezPoObrascu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunZaRegosStavke_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunZaRegosStavke_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunZaRegosStavke_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwObracunZaRegosStavke view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunZaRegosStavke_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[RedniBrojRetka],
					[RedniBrojStranice],
					[RedniBrojOsobeUObracunu],
					[OIB],
					[PunoIme],
					[SifraOpcineRegos],
					[IDObracunOsoba],
					[Sifra],
					[StazSPovecanimTrajanjem],
					[datPocetak],
					[DatKraj],
					[Bruto],
					[OsnovicazaDoprinos],
					[MIO1],
					[MIO2],
					[SamoNetoIznos],
					[IBObveznika],
					[RedniBrojUGodini],
					[Godina],
					[RedniBrojStavkeUOsobiUObracunu]
				FROM
					[pla].[vwObracunZaRegosStavke]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwObracunZaRegosStavke_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwObracunZaRegosStavke_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwObracunZaRegosStavke_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwObracunZaRegosStavke view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwObracunZaRegosStavke_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [RedniBrojRetka]'
				SET @SQL = @SQL + ', [RedniBrojStranice]'
				SET @SQL = @SQL + ', [RedniBrojOsobeUObracunu]'
				SET @SQL = @SQL + ', [OIB]'
				SET @SQL = @SQL + ', [PunoIme]'
				SET @SQL = @SQL + ', [SifraOpcineRegos]'
				SET @SQL = @SQL + ', [IDObracunOsoba]'
				SET @SQL = @SQL + ', [Sifra]'
				SET @SQL = @SQL + ', [StazSPovecanimTrajanjem]'
				SET @SQL = @SQL + ', [datPocetak]'
				SET @SQL = @SQL + ', [DatKraj]'
				SET @SQL = @SQL + ', [Bruto]'
				SET @SQL = @SQL + ', [OsnovicazaDoprinos]'
				SET @SQL = @SQL + ', [MIO1]'
				SET @SQL = @SQL + ', [MIO2]'
				SET @SQL = @SQL + ', [SamoNetoIznos]'
				SET @SQL = @SQL + ', [IBObveznika]'
				SET @SQL = @SQL + ', [RedniBrojUGodini]'
				SET @SQL = @SQL + ', [Godina]'
				SET @SQL = @SQL + ', [RedniBrojStavkeUOsobiUObracunu]'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunZaRegosStavke]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [RedniBrojRetka],'
				SET @SQL = @SQL + ' [RedniBrojStranice],'
				SET @SQL = @SQL + ' [RedniBrojOsobeUObracunu],'
				SET @SQL = @SQL + ' [OIB],'
				SET @SQL = @SQL + ' [PunoIme],'
				SET @SQL = @SQL + ' [SifraOpcineRegos],'
				SET @SQL = @SQL + ' [IDObracunOsoba],'
				SET @SQL = @SQL + ' [Sifra],'
				SET @SQL = @SQL + ' [StazSPovecanimTrajanjem],'
				SET @SQL = @SQL + ' [datPocetak],'
				SET @SQL = @SQL + ' [DatKraj],'
				SET @SQL = @SQL + ' [Bruto],'
				SET @SQL = @SQL + ' [OsnovicazaDoprinos],'
				SET @SQL = @SQL + ' [MIO1],'
				SET @SQL = @SQL + ' [MIO2],'
				SET @SQL = @SQL + ' [SamoNetoIznos],'
				SET @SQL = @SQL + ' [IBObveznika],'
				SET @SQL = @SQL + ' [RedniBrojUGodini],'
				SET @SQL = @SQL + ' [Godina],'
				SET @SQL = @SQL + ' [RedniBrojStavkeUOsobiUObracunu]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwObracunZaRegosStavke]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwOrganizacijaTV_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwOrganizacijaTV_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwOrganizacijaTV_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwOrganizacijaTV view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwOrganizacijaTV_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[TVNaziv],
					[SifraSkladista],
					[IDRoditelj],
					[Grupa],
					[IDTip],
					[Lvl],
					[Hierarchy]
				FROM
					[dbo].[vwOrganizacijaTV]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwOrganizacijaTV_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwOrganizacijaTV_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwOrganizacijaTV_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwOrganizacijaTV view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwOrganizacijaTV_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [TVNaziv]'
				SET @SQL = @SQL + ', [SifraSkladista]'
				SET @SQL = @SQL + ', [IDRoditelj]'
				SET @SQL = @SQL + ', [Grupa]'
				SET @SQL = @SQL + ', [IDTip]'
				SET @SQL = @SQL + ', [Lvl]'
				SET @SQL = @SQL + ', [Hierarchy]'
				SET @SQL = @SQL + ' FROM [dbo].[vwOrganizacijaTV]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [TVNaziv],'
				SET @SQL = @SQL + ' [SifraSkladista],'
				SET @SQL = @SQL + ' [IDRoditelj],'
				SET @SQL = @SQL + ' [Grupa],'
				SET @SQL = @SQL + ' [IDTip],'
				SET @SQL = @SQL + ' [Lvl],'
				SET @SQL = @SQL + ' [Hierarchy]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwOrganizacijaTV]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwOsnovnaSredstva_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwOsnovnaSredstva_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwOsnovnaSredstva_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwOsnovnaSredstva view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwOsnovnaSredstva_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[Sifra],
					[NazivOS],
					[VezaNAOS],
					[KontoNabave],
					[KontoTroska],
					[KontoIspravka],
					[AmortStopa],
					[AmortGrupa],
					[ZaduzenaOsoba],
					[MjestoTroska],
					[DatumKnjizenja],
					[DatumAktivacije],
					[DatumZadnjegObracunaOtpis],
					[NabVrijednost],
					[SadasnjaVrijed],
					[ZadnjaAmortizacija],
					[SaldoIspravka],
					[Opis],
					[Napomena],
					[Dobavljac],
					[GrupaOS],
					[Kolicina],
					[Tip],
					[RB],
					[OSID],
					[OSParentID],
					[OSKarticaID],
					[OSAmortID],
					[OsobaID],
					[MjestoTroskaID],
					[OSKarticaStatus]
				FROM
					[fin].[vwOsnovnaSredstva]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwOsnovnaSredstva_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwOsnovnaSredstva_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwOsnovnaSredstva_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwOsnovnaSredstva view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwOsnovnaSredstva_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Sifra]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Sifra]'
				SET @SQL = @SQL + ', [NazivOS]'
				SET @SQL = @SQL + ', [VezaNAOS]'
				SET @SQL = @SQL + ', [KontoNabave]'
				SET @SQL = @SQL + ', [KontoTroska]'
				SET @SQL = @SQL + ', [KontoIspravka]'
				SET @SQL = @SQL + ', [AmortStopa]'
				SET @SQL = @SQL + ', [AmortGrupa]'
				SET @SQL = @SQL + ', [ZaduzenaOsoba]'
				SET @SQL = @SQL + ', [MjestoTroska]'
				SET @SQL = @SQL + ', [DatumKnjizenja]'
				SET @SQL = @SQL + ', [DatumAktivacije]'
				SET @SQL = @SQL + ', [DatumZadnjegObracunaOtpis]'
				SET @SQL = @SQL + ', [NabVrijednost]'
				SET @SQL = @SQL + ', [SadasnjaVrijed]'
				SET @SQL = @SQL + ', [ZadnjaAmortizacija]'
				SET @SQL = @SQL + ', [SaldoIspravka]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [Dobavljac]'
				SET @SQL = @SQL + ', [GrupaOS]'
				SET @SQL = @SQL + ', [Kolicina]'
				SET @SQL = @SQL + ', [Tip]'
				SET @SQL = @SQL + ', [RB]'
				SET @SQL = @SQL + ', [OSID]'
				SET @SQL = @SQL + ', [OSParentID]'
				SET @SQL = @SQL + ', [OSKarticaID]'
				SET @SQL = @SQL + ', [OSAmortID]'
				SET @SQL = @SQL + ', [OsobaID]'
				SET @SQL = @SQL + ', [MjestoTroskaID]'
				SET @SQL = @SQL + ', [OSKarticaStatus]'
				SET @SQL = @SQL + ' FROM [fin].[vwOsnovnaSredstva]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Sifra],'
				SET @SQL = @SQL + ' [NazivOS],'
				SET @SQL = @SQL + ' [VezaNAOS],'
				SET @SQL = @SQL + ' [KontoNabave],'
				SET @SQL = @SQL + ' [KontoTroska],'
				SET @SQL = @SQL + ' [KontoIspravka],'
				SET @SQL = @SQL + ' [AmortStopa],'
				SET @SQL = @SQL + ' [AmortGrupa],'
				SET @SQL = @SQL + ' [ZaduzenaOsoba],'
				SET @SQL = @SQL + ' [MjestoTroska],'
				SET @SQL = @SQL + ' [DatumKnjizenja],'
				SET @SQL = @SQL + ' [DatumAktivacije],'
				SET @SQL = @SQL + ' [DatumZadnjegObracunaOtpis],'
				SET @SQL = @SQL + ' [NabVrijednost],'
				SET @SQL = @SQL + ' [SadasnjaVrijed],'
				SET @SQL = @SQL + ' [ZadnjaAmortizacija],'
				SET @SQL = @SQL + ' [SaldoIspravka],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [Dobavljac],'
				SET @SQL = @SQL + ' [GrupaOS],'
				SET @SQL = @SQL + ' [Kolicina],'
				SET @SQL = @SQL + ' [Tip],'
				SET @SQL = @SQL + ' [RB],'
				SET @SQL = @SQL + ' [OSID],'
				SET @SQL = @SQL + ' [OSParentID],'
				SET @SQL = @SQL + ' [OSKarticaID],'
				SET @SQL = @SQL + ' [OSAmortID],'
				SET @SQL = @SQL + ' [OsobaID],'
				SET @SQL = @SQL + ' [MjestoTroskaID],'
				SET @SQL = @SQL + ' [OSKarticaStatus]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwOsnovnaSredstva]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwOsoba_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwOsoba_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwOsoba_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwOsoba view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwOsoba_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Prezime],
					[Ime],
					[MjesoRodenjaNaziv],
					[MBG],
					[OIB],
					[DatumRodenja],
					[Napomena],
					[OsobniOdbitak],
					[TrenutnoRadnoMjesto],
					[TrenutniRadniOdnosTip],
					[TrenutnoMjestoBoravista],
					[TrenutnaOrganizacijskaJedinica]
				FROM
					[pla].[vwOsoba]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the pla.vwOsoba_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'pla.vwOsoba_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE pla.vwOsoba_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwOsoba view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE pla.vwOsoba_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Prezime]'
				SET @SQL = @SQL + ', [Ime]'
				SET @SQL = @SQL + ', [MjesoRodenjaNaziv]'
				SET @SQL = @SQL + ', [MBG]'
				SET @SQL = @SQL + ', [OIB]'
				SET @SQL = @SQL + ', [DatumRodenja]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [OsobniOdbitak]'
				SET @SQL = @SQL + ', [TrenutnoRadnoMjesto]'
				SET @SQL = @SQL + ', [TrenutniRadniOdnosTip]'
				SET @SQL = @SQL + ', [TrenutnoMjestoBoravista]'
				SET @SQL = @SQL + ', [TrenutnaOrganizacijskaJedinica]'
				SET @SQL = @SQL + ' FROM [pla].[vwOsoba]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Prezime],'
				SET @SQL = @SQL + ' [Ime],'
				SET @SQL = @SQL + ' [MjesoRodenjaNaziv],'
				SET @SQL = @SQL + ' [MBG],'
				SET @SQL = @SQL + ' [OIB],'
				SET @SQL = @SQL + ' [DatumRodenja],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [OsobniOdbitak],'
				SET @SQL = @SQL + ' [TrenutnoRadnoMjesto],'
				SET @SQL = @SQL + ' [TrenutniRadniOdnosTip],'
				SET @SQL = @SQL + ' [TrenutnoMjestoBoravista],'
				SET @SQL = @SQL + ' [TrenutnaOrganizacijskaJedinica]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [pla].[vwOsoba]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwParametriKorisnika_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwParametriKorisnika_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwParametriKorisnika_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwParametriKorisnika view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwParametriKorisnika_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[Param],
					[Vrijednost]
				FROM
					[dbo].[vwParametriKorisnika]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwParametriKorisnika_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwParametriKorisnika_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwParametriKorisnika_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwParametriKorisnika view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwParametriKorisnika_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Param]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Param]'
				SET @SQL = @SQL + ', [Vrijednost]'
				SET @SQL = @SQL + ' FROM [dbo].[vwParametriKorisnika]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Param],'
				SET @SQL = @SQL + ' [Vrijednost]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwParametriKorisnika]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwPopisPutnihNaloga_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwPopisPutnihNaloga_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwPopisPutnihNaloga_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwPopisPutnihNaloga view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwPopisPutnihNaloga_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[PutniNalogStatus],
					[IDStatus],
					[RedBr],
					[Oznaka],
					[Djelatnik],
					[Datum],
					[DatumObracuna],
					[DatumBlagajna],
					[ZadnjiDatumAkontacije],
					[Napomena],
					[Opis],
					[PredvidenoTrajanjeDana],
					[akontacija],
					[dnevnice],
					[ostalo],
					[prijevoz],
					[Ukupno],
					[DatumOdlaska],
					[DatumDolaska],
					[IDDjelatnikBlagajna],
					[DjelatnikBlagajnaPrikaznoIme],
					[IDDjelatnikLikvidirao],
					[DjelatnikLikvidiraoPrikaznoIme],
					[IDDjelatnikOdobrio],
					[DjelatnikOdobrioPrikaznoIme]
				FROM
					[fin].[vwPopisPutnihNaloga]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwPopisPutnihNaloga_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwPopisPutnihNaloga_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwPopisPutnihNaloga_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwPopisPutnihNaloga view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwPopisPutnihNaloga_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [PutniNalogStatus]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [Djelatnik]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [DatumObracuna]'
				SET @SQL = @SQL + ', [DatumBlagajna]'
				SET @SQL = @SQL + ', [ZadnjiDatumAkontacije]'
				SET @SQL = @SQL + ', [Napomena]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [PredvidenoTrajanjeDana]'
				SET @SQL = @SQL + ', [akontacija]'
				SET @SQL = @SQL + ', [dnevnice]'
				SET @SQL = @SQL + ', [ostalo]'
				SET @SQL = @SQL + ', [prijevoz]'
				SET @SQL = @SQL + ', [Ukupno]'
				SET @SQL = @SQL + ', [DatumOdlaska]'
				SET @SQL = @SQL + ', [DatumDolaska]'
				SET @SQL = @SQL + ', [IDDjelatnikBlagajna]'
				SET @SQL = @SQL + ', [DjelatnikBlagajnaPrikaznoIme]'
				SET @SQL = @SQL + ', [IDDjelatnikLikvidirao]'
				SET @SQL = @SQL + ', [DjelatnikLikvidiraoPrikaznoIme]'
				SET @SQL = @SQL + ', [IDDjelatnikOdobrio]'
				SET @SQL = @SQL + ', [DjelatnikOdobrioPrikaznoIme]'
				SET @SQL = @SQL + ' FROM [fin].[vwPopisPutnihNaloga]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [PutniNalogStatus],'
				SET @SQL = @SQL + ' [IDStatus],'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [Djelatnik],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [DatumObracuna],'
				SET @SQL = @SQL + ' [DatumBlagajna],'
				SET @SQL = @SQL + ' [ZadnjiDatumAkontacije],'
				SET @SQL = @SQL + ' [Napomena],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [PredvidenoTrajanjeDana],'
				SET @SQL = @SQL + ' [akontacija],'
				SET @SQL = @SQL + ' [dnevnice],'
				SET @SQL = @SQL + ' [ostalo],'
				SET @SQL = @SQL + ' [prijevoz],'
				SET @SQL = @SQL + ' [Ukupno],'
				SET @SQL = @SQL + ' [DatumOdlaska],'
				SET @SQL = @SQL + ' [DatumDolaska],'
				SET @SQL = @SQL + ' [IDDjelatnikBlagajna],'
				SET @SQL = @SQL + ' [DjelatnikBlagajnaPrikaznoIme],'
				SET @SQL = @SQL + ' [IDDjelatnikLikvidirao],'
				SET @SQL = @SQL + ' [DjelatnikLikvidiraoPrikaznoIme],'
				SET @SQL = @SQL + ' [IDDjelatnikOdobrio],'
				SET @SQL = @SQL + ' [DjelatnikOdobrioPrikaznoIme]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwPopisPutnihNaloga]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwPreostaloZaZatvaranje_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwPreostaloZaZatvaranje_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwPreostaloZaZatvaranje_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwPreostaloZaZatvaranje view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwPreostaloZaZatvaranje_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKnjizenjeStavka],
					[IDOrg],
					[SifraSkladista],
					[DatumDospijeca],
					[DatumDokumentaOriginal],
					[SifraOriginalnogDokumenta],
					[Nalog],
					[Poziv],
					[KontoSifra],
					[KontoNaziv],
					[VrstaFinDokNaziv],
					[VrstaDokSifra],
					[ImeKlijenta],
					[MB],
					[Dug],
					[Pot],
					[Preostalo],
					[IDStatus]
				FROM
					[fin].[vwPreostaloZaZatvaranje]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwPreostaloZaZatvaranje_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwPreostaloZaZatvaranje_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwPreostaloZaZatvaranje_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwPreostaloZaZatvaranje view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwPreostaloZaZatvaranje_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDKnjizenjeStavka]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDKnjizenjeStavka]'
				SET @SQL = @SQL + ', [IDOrg]'
				SET @SQL = @SQL + ', [SifraSkladista]'
				SET @SQL = @SQL + ', [DatumDospijeca]'
				SET @SQL = @SQL + ', [DatumDokumentaOriginal]'
				SET @SQL = @SQL + ', [SifraOriginalnogDokumenta]'
				SET @SQL = @SQL + ', [Nalog]'
				SET @SQL = @SQL + ', [Poziv]'
				SET @SQL = @SQL + ', [KontoSifra]'
				SET @SQL = @SQL + ', [KontoNaziv]'
				SET @SQL = @SQL + ', [VrstaFinDokNaziv]'
				SET @SQL = @SQL + ', [VrstaDokSifra]'
				SET @SQL = @SQL + ', [ImeKlijenta]'
				SET @SQL = @SQL + ', [MB]'
				SET @SQL = @SQL + ', [Dug]'
				SET @SQL = @SQL + ', [Pot]'
				SET @SQL = @SQL + ', [Preostalo]'
				SET @SQL = @SQL + ', [IDStatus]'
				SET @SQL = @SQL + ' FROM [fin].[vwPreostaloZaZatvaranje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDKnjizenjeStavka],'
				SET @SQL = @SQL + ' [IDOrg],'
				SET @SQL = @SQL + ' [SifraSkladista],'
				SET @SQL = @SQL + ' [DatumDospijeca],'
				SET @SQL = @SQL + ' [DatumDokumentaOriginal],'
				SET @SQL = @SQL + ' [SifraOriginalnogDokumenta],'
				SET @SQL = @SQL + ' [Nalog],'
				SET @SQL = @SQL + ' [Poziv],'
				SET @SQL = @SQL + ' [KontoSifra],'
				SET @SQL = @SQL + ' [KontoNaziv],'
				SET @SQL = @SQL + ' [VrstaFinDokNaziv],'
				SET @SQL = @SQL + ' [VrstaDokSifra],'
				SET @SQL = @SQL + ' [ImeKlijenta],'
				SET @SQL = @SQL + ' [MB],'
				SET @SQL = @SQL + ' [Dug],'
				SET @SQL = @SQL + ' [Pot],'
				SET @SQL = @SQL + ' [Preostalo],'
				SET @SQL = @SQL + ' [IDStatus]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwPreostaloZaZatvaranje]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwPreostaloZaZatvaranjeZapisanoSimple_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwPreostaloZaZatvaranjeZapisanoSimple_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwPreostaloZaZatvaranjeZapisanoSimple_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwPreostaloZaZatvaranjeZapisanoSimple view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwPreostaloZaZatvaranjeZapisanoSimple_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKnjizStavkaSimpl],
					[Preostalo]
				FROM
					[fin].[vwPreostaloZaZatvaranjeZapisanoSimple]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwPreostaloZaZatvaranjeZapisanoSimple_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwPreostaloZaZatvaranjeZapisanoSimple_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwPreostaloZaZatvaranjeZapisanoSimple_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwPreostaloZaZatvaranjeZapisanoSimple view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwPreostaloZaZatvaranjeZapisanoSimple_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDKnjizStavkaSimpl]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDKnjizStavkaSimpl]'
				SET @SQL = @SQL + ', [Preostalo]'
				SET @SQL = @SQL + ' FROM [fin].[vwPreostaloZaZatvaranjeZapisanoSimple]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDKnjizStavkaSimpl],'
				SET @SQL = @SQL + ' [Preostalo]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwPreostaloZaZatvaranjeZapisanoSimple]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwPreostaloZaZatvaranjeZapisanoSimpleSvi_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwPreostaloZaZatvaranjeZapisanoSimpleSvi_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwPreostaloZaZatvaranjeZapisanoSimpleSvi_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwPreostaloZaZatvaranjeZapisanoSimpleSvi view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwPreostaloZaZatvaranjeZapisanoSimpleSvi_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKnjizStavkaSimpl],
					[Preostalo]
				FROM
					[fin].[vwPreostaloZaZatvaranjeZapisanoSimpleSvi]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwPreostaloZaZatvaranjeZapisanoSimpleSvi_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwPreostaloZaZatvaranjeZapisanoSimpleSvi_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwPreostaloZaZatvaranjeZapisanoSimpleSvi_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwPreostaloZaZatvaranjeZapisanoSimpleSvi view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwPreostaloZaZatvaranjeZapisanoSimpleSvi_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDKnjizStavkaSimpl]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDKnjizStavkaSimpl]'
				SET @SQL = @SQL + ', [Preostalo]'
				SET @SQL = @SQL + ' FROM [fin].[vwPreostaloZaZatvaranjeZapisanoSimpleSvi]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDKnjizStavkaSimpl],'
				SET @SQL = @SQL + ' [Preostalo]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwPreostaloZaZatvaranjeZapisanoSimpleSvi]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwPrijenosRadnogNaloga_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwPrijenosRadnogNaloga_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwPrijenosRadnogNaloga_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwPrijenosRadnogNaloga view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwPrijenosRadnogNaloga_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDDokument],
					[RedBr],
					[Oznaka],
					[TipSkraceniNaziv],
					[TipNaziv],
					[IDDokTip],
					[Klijent],
					[MB],
					[DjelatnikIme],
					[DjelatnikUser],
					[SkladisteSifraOd],
					[SkladisteOd],
					[Datum],
					[IDTip],
					[Naziv]
				FROM
					[dbo].[vwPrijenosRadnogNaloga]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwPrijenosRadnogNaloga_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwPrijenosRadnogNaloga_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwPrijenosRadnogNaloga_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwPrijenosRadnogNaloga view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwPrijenosRadnogNaloga_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDDokument]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDDokument]'
				SET @SQL = @SQL + ', [RedBr]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [TipSkraceniNaziv]'
				SET @SQL = @SQL + ', [TipNaziv]'
				SET @SQL = @SQL + ', [IDDokTip]'
				SET @SQL = @SQL + ', [Klijent]'
				SET @SQL = @SQL + ', [MB]'
				SET @SQL = @SQL + ', [DjelatnikIme]'
				SET @SQL = @SQL + ', [DjelatnikUser]'
				SET @SQL = @SQL + ', [SkladisteSifraOd]'
				SET @SQL = @SQL + ', [SkladisteOd]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [IDTip]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ' FROM [dbo].[vwPrijenosRadnogNaloga]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDDokument],'
				SET @SQL = @SQL + ' [RedBr],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [TipSkraceniNaziv],'
				SET @SQL = @SQL + ' [TipNaziv],'
				SET @SQL = @SQL + ' [IDDokTip],'
				SET @SQL = @SQL + ' [Klijent],'
				SET @SQL = @SQL + ' [MB],'
				SET @SQL = @SQL + ' [DjelatnikIme],'
				SET @SQL = @SQL + ' [DjelatnikUser],'
				SET @SQL = @SQL + ' [SkladisteSifraOd],'
				SET @SQL = @SQL + ' [SkladisteOd],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [IDTip],'
				SET @SQL = @SQL + ' [Naziv]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwPrijenosRadnogNaloga]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwRabat_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwRabat_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwRabat_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwRabat view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwRabat_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[IDKlijent],
					[IDProizvodac],
					[IDKategorija],
					[Vrijednost],
					[IDTraziArtikl]
				FROM
					[dbo].[vwRabat]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwRabat_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwRabat_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwRabat_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwRabat view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwRabat_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [IDProizvodac]'
				SET @SQL = @SQL + ', [IDKategorija]'
				SET @SQL = @SQL + ', [Vrijednost]'
				SET @SQL = @SQL + ', [IDTraziArtikl]'
				SET @SQL = @SQL + ' FROM [dbo].[vwRabat]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [IDProizvodac],'
				SET @SQL = @SQL + ' [IDKategorija],'
				SET @SQL = @SQL + ' [Vrijednost],'
				SET @SQL = @SQL + ' [IDTraziArtikl]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwRabat]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwRadniNalogVeze_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwRadniNalogVeze_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwRadniNalogVeze_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwRadniNalogVeze view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwRadniNalogVeze_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[Od],
					[TipDokumenta],
					[Oznaka],
					[Datum],
					[IDChild],
					[IDParent],
					[IDDokumentTip],
					[IDGrupe]
				FROM
					[dbo].[vwRadniNalogVeze]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwRadniNalogVeze_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwRadniNalogVeze_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwRadniNalogVeze_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwRadniNalogVeze view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwRadniNalogVeze_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Od]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Od]'
				SET @SQL = @SQL + ', [TipDokumenta]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [IDChild]'
				SET @SQL = @SQL + ', [IDParent]'
				SET @SQL = @SQL + ', [IDDokumentTip]'
				SET @SQL = @SQL + ', [IDGrupe]'
				SET @SQL = @SQL + ' FROM [dbo].[vwRadniNalogVeze]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Od],'
				SET @SQL = @SQL + ' [TipDokumenta],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [IDChild],'
				SET @SQL = @SQL + ' [IDParent],'
				SET @SQL = @SQL + ' [IDDokumentTip],'
				SET @SQL = @SQL + ' [IDGrupe]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwRadniNalogVeze]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwReport_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwReport_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwReport_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwReport view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwReport_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Naziv],
					[IDParent],
					[SelectString],
					[Tip],
					[Kolumne],
					[Filter],
					[FilterAdv],
					[Poredak]
				FROM
					[dbo].[vwReport]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwReport_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwReport_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwReport_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwReport view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwReport_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Naziv]'
				SET @SQL = @SQL + ', [IDParent]'
				SET @SQL = @SQL + ', [SelectString]'
				SET @SQL = @SQL + ', [Tip]'
				SET @SQL = @SQL + ', [Kolumne]'
				SET @SQL = @SQL + ', [Filter]'
				SET @SQL = @SQL + ', [FilterAdv]'
				SET @SQL = @SQL + ', [Poredak]'
				SET @SQL = @SQL + ' FROM [dbo].[vwReport]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Naziv],'
				SET @SQL = @SQL + ' [IDParent],'
				SET @SQL = @SQL + ' [SelectString],'
				SET @SQL = @SQL + ' [Tip],'
				SET @SQL = @SQL + ' [Kolumne],'
				SET @SQL = @SQL + ' [Filter],'
				SET @SQL = @SQL + ' [FilterAdv],'
				SET @SQL = @SQL + ' [Poredak]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwReport]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwSKPoDokumentimaPoTipu_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwSKPoDokumentimaPoTipu_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwSKPoDokumentimaPoTipu_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwSKPoDokumentimaPoTipu view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwSKPoDokumentimaPoTipu_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[ID],
					[Kolona],
					[Opis],
					[Suma],
					[IDDokument],
					[Grupna]
				FROM
					[dbo].[vwSKPoDokumentimaPoTipu]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwSKPoDokumentimaPoTipu_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwSKPoDokumentimaPoTipu_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwSKPoDokumentimaPoTipu_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwSKPoDokumentimaPoTipu view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwSKPoDokumentimaPoTipu_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ID]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ID]'
				SET @SQL = @SQL + ', [Kolona]'
				SET @SQL = @SQL + ', [Opis]'
				SET @SQL = @SQL + ', [Suma]'
				SET @SQL = @SQL + ', [IDDokument]'
				SET @SQL = @SQL + ', [Grupna]'
				SET @SQL = @SQL + ' FROM [dbo].[vwSKPoDokumentimaPoTipu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ID],'
				SET @SQL = @SQL + ' [Kolona],'
				SET @SQL = @SQL + ' [Opis],'
				SET @SQL = @SQL + ' [Suma],'
				SET @SQL = @SQL + ' [IDDokument],'
				SET @SQL = @SQL + ' [Grupna]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwSKPoDokumentimaPoTipu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwTmpSaldoKlijenta_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwTmpSaldoKlijenta_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwTmpSaldoKlijenta_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwTmpSaldoKlijenta view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwTmpSaldoKlijenta_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKlijent],
					[Saldo],
					[SaldoDanas]
				FROM
					[dbo].[vwTmpSaldoKlijenta]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwTmpSaldoKlijenta_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwTmpSaldoKlijenta_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwTmpSaldoKlijenta_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwTmpSaldoKlijenta view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwTmpSaldoKlijenta_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDKlijent]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [Saldo]'
				SET @SQL = @SQL + ', [SaldoDanas]'
				SET @SQL = @SQL + ' FROM [dbo].[vwTmpSaldoKlijenta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [Saldo],'
				SET @SQL = @SQL + ' [SaldoDanas]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwTmpSaldoKlijenta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwVezeDokumenta_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwVezeDokumenta_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwVezeDokumenta_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwVezeDokumenta view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwVezeDokumenta_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[Od],
					[Tip dokumenta],
					[Oznaka],
					[Datum],
					[IDChild],
					[IDParent],
					[IDTip]
				FROM
					[dbo].[vwVezeDokumenta]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the dbo.vwVezeDokumenta_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.vwVezeDokumenta_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.vwVezeDokumenta_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwVezeDokumenta view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.vwVezeDokumenta_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Od]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Od]'
				SET @SQL = @SQL + ', [Tip dokumenta]'
				SET @SQL = @SQL + ', [Oznaka]'
				SET @SQL = @SQL + ', [Datum]'
				SET @SQL = @SQL + ', [IDChild]'
				SET @SQL = @SQL + ', [IDParent]'
				SET @SQL = @SQL + ', [IDTip]'
				SET @SQL = @SQL + ' FROM [dbo].[vwVezeDokumenta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Od],'
				SET @SQL = @SQL + ' [Tip dokumenta],'
				SET @SQL = @SQL + ' [Oznaka],'
				SET @SQL = @SQL + ' [Datum],'
				SET @SQL = @SQL + ' [IDChild],'
				SET @SQL = @SQL + ' [IDParent],'
				SET @SQL = @SQL + ' [IDTip]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[vwVezeDokumenta]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwVirmanOdabir_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwVirmanOdabir_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwVirmanOdabir_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets all records from the vwVirmanOdabir view
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwVirmanOdabir_Get_List

AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				SELECT
					[IDKnjizenja],
					[MT],
					[Konto],
					[MB],
					[DatumDokumenta],
					[DatumDospijeca],
					[IDKlijent],
					[NalogodavateljNaziv],
					[NalogodavateljSjediste],
					[NalogodavateljRacun],
					[BrojZaduzenjaModel],
					[BrojZaduzenjaPoziv],
					[SvrhaDoznake],
					[PrimateljNaziv],
					[PrimateljSjediste],
					[PrimateljRacun],
					[BrojOdobrenjaModel],
					[BrojOdobrenjaPoziv],
					[Iznos],
					[DatumIzvrsenja]
				FROM
					[fin].[vwVirmanOdabir]
					
				Select @@ROWCOUNT			
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

	

-- Drop the fin.vwVirmanOdabir_Get procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'fin.vwVirmanOdabir_Get') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE fin.vwVirmanOdabir_Get
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: 16. listopad 2012

-- Created By:  ()
-- Purpose: Gets records from the vwVirmanOdabir view passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE fin.vwVirmanOdabir_Get
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
				BEGIN

				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[IDKnjizenja]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [IDKnjizenja]'
				SET @SQL = @SQL + ', [MT]'
				SET @SQL = @SQL + ', [Konto]'
				SET @SQL = @SQL + ', [MB]'
				SET @SQL = @SQL + ', [DatumDokumenta]'
				SET @SQL = @SQL + ', [DatumDospijeca]'
				SET @SQL = @SQL + ', [IDKlijent]'
				SET @SQL = @SQL + ', [NalogodavateljNaziv]'
				SET @SQL = @SQL + ', [NalogodavateljSjediste]'
				SET @SQL = @SQL + ', [NalogodavateljRacun]'
				SET @SQL = @SQL + ', [BrojZaduzenjaModel]'
				SET @SQL = @SQL + ', [BrojZaduzenjaPoziv]'
				SET @SQL = @SQL + ', [SvrhaDoznake]'
				SET @SQL = @SQL + ', [PrimateljNaziv]'
				SET @SQL = @SQL + ', [PrimateljSjediste]'
				SET @SQL = @SQL + ', [PrimateljRacun]'
				SET @SQL = @SQL + ', [BrojOdobrenjaModel]'
				SET @SQL = @SQL + ', [BrojOdobrenjaPoziv]'
				SET @SQL = @SQL + ', [Iznos]'
				SET @SQL = @SQL + ', [DatumIzvrsenja]'
				SET @SQL = @SQL + ' FROM [fin].[vwVirmanOdabir]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [IDKnjizenja],'
				SET @SQL = @SQL + ' [MT],'
				SET @SQL = @SQL + ' [Konto],'
				SET @SQL = @SQL + ' [MB],'
				SET @SQL = @SQL + ' [DatumDokumenta],'
				SET @SQL = @SQL + ' [DatumDospijeca],'
				SET @SQL = @SQL + ' [IDKlijent],'
				SET @SQL = @SQL + ' [NalogodavateljNaziv],'
				SET @SQL = @SQL + ' [NalogodavateljSjediste],'
				SET @SQL = @SQL + ' [NalogodavateljRacun],'
				SET @SQL = @SQL + ' [BrojZaduzenjaModel],'
				SET @SQL = @SQL + ' [BrojZaduzenjaPoziv],'
				SET @SQL = @SQL + ' [SvrhaDoznake],'
				SET @SQL = @SQL + ' [PrimateljNaziv],'
				SET @SQL = @SQL + ' [PrimateljSjediste],'
				SET @SQL = @SQL + ' [PrimateljRacun],'
				SET @SQL = @SQL + ' [BrojOdobrenjaModel],'
				SET @SQL = @SQL + ' [BrojOdobrenjaPoziv],'
				SET @SQL = @SQL + ' [Iznos],'
				SET @SQL = @SQL + ' [DatumIzvrsenja]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				exec sp_executesql @SQL

				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [fin].[vwVirmanOdabir]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
				
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

